MicroK8s is production grade Kubernetes platform. It is simple to setup cluster or single node instance for testing or simple production apps.
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.
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}"
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
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