Set up Kubernetes in Ubuntu (single host cluster)

Page content

Pre-requirement of this post

  • Host OS: Ubuntu18.04
  • snapd is install (for snapcraft.)
  • Kubernetes is abbreviated as k8s.
  • For single host k8s environment, there is a good k8s implementation called microk8s. I’ll use it.

Setup on Ubuntu

Install Docker and microk8s

Install softwares, Docker and microk8s.

sudo snap install docker
sudo snap install microk8s --classic --channel=1.18/stable

Granting permission

sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube

After re-login, check the k8s status.

microk8s status --wait-ready

Set useful alias at ~/.bashrc.

alias kubectl='microk8s kubectl'

Enabling features (add-ons)

microk8s enable dns storage registry ingress istio dashboard
(at istio TLS sidecar NO)
  • dns: “Deploys CoreDNS”
  • storage: “Create a default storage class which allocates storage from a host directory.”
  • registry: “Deploy a private image registry and expose it on localhost:32000.”
  • ingress: “A simple ingress controller for external access.”
  • istio: “Adds the core Istio services.”
  • dashboard: Convenient way to keep track of the activity and resource use of Microk8s.

Refer to the official document.

Get a cluster information

Access to the cluster (SSL portforwarded in my caes, like ssh -L 50443:localhost:16443 atlex@remote-k8s-host.com. The localhost here means remote.com). You can see credentials for BasicAuth with kubectl config view.

atlex@remote:~$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:16443
CoreDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
...

Remark: The TLS certificate is self signed.

Check objects in k8s cluster

Check the default objects.

kubectl get nodes
kubectl get pods
kubectl get services
kubectl get deplotment
kubectl get all

Note: Default objects.

$ kubectl get all --all-namespaces
NAMESPACE   NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
default     service/kubernetes   ClusterIP   10.152.183.1   <none>        443/TCP   50m

Stop microk8s

microk8s stop

Reset coniguration

Completely reset from initial microk8s state. All related data will be discareded.

microk8s reset --destroy-storage

Some Pods can’t be deleted automatically, so I deleted them manually.

kubectl get all --all-namespaces
kubectl delete pod/heapster-v1.5.2-58fdbb6f4d-tktq7 --grace-period=0 --force -n -system

Check microk8s status

microk8s status

Delete from the server

sudo snap remove microk8s

Memo

for dashboard.