Installing Microk8s on Ubuntu 18.04 (Bionic)
As we are working with Ubuntu, let's install the snap to handle the microk8s installation
sudo apt-get update && apt-get install snap -y
Now we need to install the microk8s
sudo snap install microk8s --classic
After the installation we need to enable the non-root user be able to handle the microk8s
sudo usermod -a -G microk8s <username>
Now let's create an alias to make it more easy to type
echo "alias kubectl='microk8s.kubectl'" >> ~/.bashrc
Now we need to log out and back in.
Now after log in again let's check the status of the microk8s
microk8s.status --wait-ready microk8s is running addons: dns: disabled cilium: disabled dashboard: disabled fluentd: disabled gpu: disabled helm: disabled helm3: disabled ingress: disabled istio: disabled jaeger: disabled knative: disabled kubeflow: disabled linkerd: disabled metallb: disabled metrics-server: disabled prometheus: disabled rbac: disabled registry: disabled storage: disabled
Now let's enable the CoreDNS
microk8s.enable dns
Now we need to store the microk8s configuration as follows
microk8s.kubectl config view --raw > $HOME/.kube/config
Now we need to adjust the iptables configuration, let's enable the FORWARD as ACCEPT
sudo iptables -P FORWARD ACCEPT
Now we need to install the iptables-persistent package that is need as dependency
sudo apt-get install iptables-persistent
I will be using the Docker as Container Runtime, we need to configure it
vim /etc/docker/daemon.json { "insecure-registries" : ["localhost:32000"] }
Now we need to restart the Docker Service
systemctl restart docker
Now we are ok to get start :D
Dashboard addon
Note: By Default the Google Chrome will not enable your access to the interface, you can use the FireFox Browser though.
The standard Kubernetes Dashboard is a convenient way to keep track of the activity and resource use of MicroK8s
microk8s enable dashboard Applying manifest serviceaccount/kubernetes-dashboard created service/kubernetes-dashboard created secret/kubernetes-dashboard-certs created secret/kubernetes-dashboard-csrf created secret/kubernetes-dashboard-key-holder created configmap/kubernetes-dashboard-settings created role.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created deployment.apps/kubernetes-dashboard created service/dashboard-metrics-scraper created deployment.apps/dashboard-metrics-scraper created service/monitoring-grafana created service/monitoring-influxdb created service/heapster created deployment.apps/monitoring-influxdb-grafana-v4 created serviceaccount/heapster created clusterrolebinding.rbac.authorization.k8s.io/heapster created configmap/heapster-config created configmap/eventer-config created deployment.apps/heapster-v1.5.2 created If RBAC is not enabled access the dashboard using the default token retrieved with: token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1) microk8s kubectl -n kube-system describe secret $token In an RBAC enabled setup (microk8s enable RBAC) you need to create a user with restricted permissions as shown in: https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md
Now we need to create the Token
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
Now we neeed to get the output to log in
microk8s kubectl -n kube-system describe secret $token Name: default-token-wczsp Namespace: kube-system Labels: <none> Annotations: kubernetes.io/service-account.name: default kubernetes.io/service-account.uid: 24ff2f4e-e0c1-4391-9974-2d48cea20106 Type: kubernetes.io/service-account-token Data ==== namespace: 11 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImVmRUFTallpSFJpUlAtVWFKSGZsWjB1ODgwYlpyVkE1U0lHbVVQYnd4NTgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkZWZhdWx0LXRva2VuLXdjenNwIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImRlZmF1bHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyNGZmMmY0ZS1lMGMxLTQzOTEtOTk3NC0yZDQ4Y2VhMjAxMDYiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06ZGVmYXVsdCJ9.Nuk-nue84uxd16d7vms5DYMxjKtex31EfQ8UgV6mTIhWsxX_dUCFOS0TlrZXoT4aQQIy5GNt7uYQV6t_MKFLxlSw1961N0NP0yNLzbnL_QH2LoBWEEd9orrYOrlD5XBJMyICUkXKq_ISCNbd51sQjPrErY3KxD6ncATQxD1R9T1vH46VZrKcSjBgOGjD-Xnb9kG_0KBwxbuPCKayAsN8m8hr3K6uZNzKb1V89F2Dn1pw5AL8kRPuSG90esdSrnoQTWoCwicZ9PsoQhUVyxAW6PM3NJmW9AWQyo4fbsc7ksLG7x7QFeWjfyyp6jRo0KtD6gvQPe0PRrEcy2l61OmFHQ ca.crt: 1103 bytes
Next, you need to connect to the dashboard service. While the MicroK8s snap will have an IP address on your local network (the Cluster IP of the kubernetes-dashboard service), you can also reach the dashboard by forwarding its port to a free one on your host with:
microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443
You can then access the Dashboard at https://127.0.0.1:10443
you are running MicroK8s in a VM and you need to expose the Dashboard to other hosts, you should also use the –address [IP_address_that_your_browser's_host_has] option. Set this option to –address 0.0.0.0 to make the Dashboard public. For example:
microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443 --address 0.0.0.0 Forwarding from 0.0.0.0:10443 -> 8443
Now we can access https://hostip:10443 we will get the dashboard authentication and we need to put the token and click sign in
After that we'll get the main dashboard page.
Visit the upstream dashboard documentation to find out other ways to reach the