About MicroK8S:
MicroK8s is a CNCF certified upstream Kubernetes deployment that runs entirely on workstation or edge device. Being a snap it runs all Kubernetes services natively (i.e. no virtual machines) while packing the entire set of libraries and binaries needed. Installation is limited by how fast you can download a couple of hundred megabytes and the removal of MicroK8s leaves nothing behind.1. Requirement:
One Linux machine with Ubuntu Installed.
2. Deployment of Microk8s:
4. Enable Add-ons:
We need to point our browser to
sudo snap install microk8s --classic
MicroK8s is a snap and as such it is frequently updated to each release of Kubernetes. To follow a specific upstream release series it’s possible to select a channel during installation. For example, to follow the v1.17 series:
sudo snap install microk8s --classic --channel=1.17/stable
snap info microk8s to see what versions are currently published.
name: microk8s
summary: Kubernetes for workstations and appliances
publisher: Canonical*
store-url: https://snapcraft.io/microk8s
contact: https://github.com/ubuntu/microk8s
license: unset
description: |
MicroK8s is a small, fast, secure, single node Kubernetes that installs on
just about any Linux box. Use it for offline development, prototyping,
testing, or use it on a VM as a small, cheap, reliable k8s for CI/CD. It's
also a great k8s for appliances - develop your IoT apps for k8s and deploy
them to MicroK8s on your boxes.
commands:
- microk8s.add-node
- microk8s.cilium
- microk8s.config
- microk8s.ctr
- microk8s.disable
- microk8s.enable
- microk8s.helm
- microk8s.inspect
- microk8s.istioctl
- microk8s.join
- microk8s.juju
- microk8s.kubectl
- microk8s.leave
- microk8s.linkerd
- microk8s
- microk8s.remove-node
- microk8s.reset
- microk8s.start
- microk8s.status
- microk8s.stop
services:
microk8s.daemon-apiserver: simple, disabled, inactive
microk8s.daemon-apiserver-kicker: simple, disabled, inactive
microk8s.daemon-cluster-agent: simple, disabled, inactive
microk8s.daemon-containerd: simple, disabled, inactive
microk8s.daemon-controller-manager: simple, disabled, inactive
microk8s.daemon-etcd: simple, disabled, inactive
microk8s.daemon-flanneld: simple, disabled, inactive
microk8s.daemon-kubelet: simple, disabled, inactive
microk8s.daemon-proxy: simple, disabled, inactive
microk8s.daemon-scheduler: simple, disabled, inactive
snap-id: EaXqgt1lyCaxKaQCU349mlodBkDCXRcg
tracking: 1.17/stable
refresh-date: today at 09:46 IST
channels:
latest/stable: v1.18.2 2020-04-27 (1378) 201MB classic
latest/candidate: v1.18.2 2020-04-30 (1383) 201MB classic
latest/beta: v1.18.2 2020-04-30 (1383) 201MB classic
latest/edge: v1.18.2 2020-05-01 (1391) 211MB classic
dqlite/stable: --
dqlite/candidate: --
dqlite/beta: --
dqlite/edge: v1.16.2 2019-11-07 (1038) 189MB classic
1.19/stable: --
1.19/candidate: --
1.19/beta: --
1.19/edge: v1.19.0-alpha.1 2020-03-26 (1311) 201MB classic
1.18/stable: v1.18.2 2020-04-27 (1379) 201MB classic
1.18/candidate: v1.18.2 2020-04-27 (1379) 201MB classic
1.18/beta: v1.18.2 2020-04-27 (1379) 201MB classic
1.18/edge: v1.18.2 2020-04-29 (1387) 201MB classic
1.17/stable: v1.17.5 2020-05-02 (1355) 179MB classic
1.17/candidate: v1.17.5 2020-04-17 (1355) 179MB classic
1.17/beta: v1.17.5 2020-04-17 (1355) 179MB classic
1.17/edge: v1.17.5 2020-04-29 (1388) 179MB classic
1.16/stable: v1.16.8 2020-03-27 (1302) 179MB classic
1.16/candidate: v1.16.8 2020-03-27 (1302) 179MB classic
3. Configure your firewall to allow pod-to-pod and pod-to-internet communication:
sudo ufw allow in on cni0 && sudo ufw allow out on cni0
sudo ufw default allow routed
By default we get a barebones upstream Kubernetes. Additional services, such as dashboard or kube-dns, can be enabled by running the
microk8s.enable command:microk8s.enable dashboard dns
These addons can be disabled at anytime by running the
microk8s.disable command:microk8s.disable dashboard dns
With
microk8s.status you can see the list of available addons and the ones currently enabled.List of the most important addons
- dns: Deploy DNS. This addon may be required by others, thus we recommend you always enable it.
- dashboard: Deploy kubernetes dashboard as well as grafana and influxdb.
- storage: Create a default storage class. This storage class makes use of the hostpath-provisioner pointing to a directory on the host.
- ingress: Create an ingress controller.
- gpu: Expose GPU(s) to MicroK8s by enabling the nvidia-docker runtime and nvidia-device-plugin-daemonset. Requires NVIDIA drivers to be already installed on the host system.
- istio: Deploy the core Istio services. You can use the
microk8s.istioctlcommand to manage your deployments. - registry: Deploy a docker private registry and expose it on localhost:32000. The storage addon will be enabled as part of this addon.
4. Accessing the Kubernetes and Grafana dashboards:
microk8s.kubectl get all --all-namespaces
5. Access Kubernetes and Grafana dashboard:
Refer above snapshot. To access dashboard open in your browser to
https://10.152.183.46:443 and you will see the kubernetes dashboard UI. To access the dashboard use 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
To access Grafana dashboard:
microk8s.kubectl cluster-info
https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy and use the username and password shown with microk8s.config.
6. Host your first service in Kubernetes
We start by creating a microbot deployment with two pods via the kubectl cli:
microk8s.kubectl create deployment microbot --image=dontrebootme/microbot:v1
microk8s.kubectl scale deployment microbot --replicas=2
To expose our deployment we need to create a service:
microk8s.kubectl expose deployment microbot --type=NodePort --port=80 --name=microbot-service
microk8s.kubectl get all --all-namespaces
you will see the service "microbot-service" which is accessible on port "80" of Node IP.
7. Useful additional commands:
There are many commands that ship with MicroK8s. We’ve only seen the essential ones in this tutorial. Explore the others at your own convenience:
- microk8s.status: Provides an overview of the MicroK8s state (running / not running) as well as the set of enabled addons
- microk8s.enable: Enables an addon
- microk8s.disable: Disables an addon
- microk8s.kubectl: Interact with kubernetes
- microk8s.config: Shows the kubernetes config file
- microk8s.istioctl: Interact with the istio services; needs the istio addon to be enabled
- microk8s.inspect: Performs a quick inspection of the MicroK8s intallation
- microk8s.reset: Resets the infrastructure to a clean state
- microk8s.stop: Stops all kubernetes services
- microk8s.start: Starts MicroK8s after it is being stopped
8. Finally, once you have enough dirty hand with MicroK8s, don't forget to stop cluster with "microk8s.stop"
9. Build-in inspection tool:
sudo microk8s inspect
10. Checking Pods logs:
microk8s kubectl get pods
microk8s kubectl logs
# All images running in a cluster kubectl get pods -A -o=custom-columns='DATA:spec.containers[*].image' # All images excluding "k8s.gcr.io/coredns:1.6.2" kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="k8s.gcr.io/coredns:1.6.2")].image' # All fields under metadata regardless of name kubectl get pods -A -o=custom-columns='DATA:metadata.*'
No comments:
Post a Comment