Docker & Kubernetes
Containers

Programming

Microservices

High Availability

SRE | Hetzner Load balancing Nginx, Keepalived

Kubernetes in the Wild

Intro

MicroK8s is production grade Kubernetes platform. It is simple to setup cluster or single node instance for testing or simple production apps.

Install

	
	snap install microk8s --classic
					

This installed MicroK8s in my Ubuntu host, but command:

	
	microk8s kubectl get pods
				

was not available. Had to change to root user to run it and add my user to micork8s group.

Configure

After installation bunch of ports are open on the public IP address of the host. Several Kubernetes addons should be enabled. This can be done using the script:

    
	#!/bin/bash

	DNS_SERVER=1.1.1.1
	HOST_PUBLIC_IP="YOUR.PUBLIC.IP"
	
	# Make single node cluster
	microk8s disable ha-cluster --force
	
	microk8s enable hostpath-storage
	microk8s enable dns:"$DNS_SERVER"
	microk8s enable cert-manager
	microk8s enable rbac
	microk8s enable metallb:"${HOST_PUBLIC_IP}-${HOST_PUBLIC_IP}"
    

Docker Registry

My Kubernetes will be connected to the GitLab DockerRegistry. Here is how to create Secrets and configure access using Personal Access Token created in the Gitlab:


        $ kubectl --namespace default  create secret docker-registry image-registry-credentials --docker-username="<your username here>" --docker-password="<your password here>" --docker-server=registry.gitlab.com				
    

Deploy the App

Create the Deployment, ie. app-deployment.yaml


        kind: Deployment
        metadata:
          name: sre-app
        spec:
          replicas: 1
          selector:
            matchLabels:
              app: sre-app
          template:
            metadata:
              labels:
                app: sre-app
                label-key: sre-app-key
            spec:
              imagePullSecrets:
                - name: image-registry-credentials
              containers:
                - name: sre-app-container
                  image: YOUR_REGISTRY/YOUR_APP
                  imagePullPolicy: Always
                  ports:
                    - containerPort: 3000
    

Create the Service, ie. app-service.yaml

    
        apiVersion: v1
        kind: Service
        metadata: 
            name: sre-app-service
        spec:
            type: LoadBalancer
            ports:
                - name: http
                port: 80
                targetPort: 3000
                protocol: TCP
            selector:
                app: sre-app
    

Run:

    
        kubectl apply -f app-deployment.yaml
        kubectl apply -f app-service.yaml