Kubernetes is the most trending container-orchestration system that can be used to automating application deployment, scaling and management. But you can not deploy Kubernetes easily it can be very expensive. MicroK8s is an upstream Kubernetes deployment that allows you to run Kubernetes in Snap. MicroK8s is a single package that runs on all major Linux-based operating systems. It comes with a docker registry so you can easily create, push and deploy containers on your system. Microk8s is a fast, lightweight and runs all Kubernetes services natively.
In this tutorial, we will learn how to install MicroK8s and get your Kuberenetes cluster up and running.
Requirements
- A cloud server running with Ubuntu 22.04 and 4 GB RAM.
- A root password set up on your cloud vps server.
Starting
First, update your server to the last versión with the following command:
# apt-get update && apt-get upgrade -y
Once your cloud server is updated, restart it to apply all the changes.
Install MicroK8s
First, you'll need to install Snap in order to install afterwards MicroK8s. You can install Snap with the following command:
# apt-get install snapd -y
Once Snap has been installed, you can install MicroK8s using the Snap command as it is shown below:
# snap install microk8s --classic
Once MikroK8s has been installed, you can check the MicroK8s information with the following command:
# snap info microk8s
You should see the following result:
name: microk8s
summary: Kubernetes for workstations and appliances
publisher: Canonical✓
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.
You can also check the MicroK8s deployment state with the following command:
# microk8s.status
You can check the MicroK8s state with the available addons in the following result:
microk8s is running
addons:
knative: disabled
jaeger: disabled
fluentd: disabled
gpu: disabled
storage: disabled
registry: disabled
rbac: disabled
ingress: disabled
dns: disabled
metrics-server: disabled
linkerd: disabled
prometheus: disabled
istio: disabled
dashboard: disabled
To check the cluster information, you can do it with the following command:
# microk8s.kubectl cluster-info
You should see the following result:
Kubernetes master is running at https://127.0.0.1:16443
To diagnose and debug possible cluster problems, use ‘kubectl cluster-info dump’.
Working with MicroK8s
You can also list the MicroK8s nodes with the following command:
# microk8s.kubectl get nodes
You should see the following command:
NAME STATUS ROLES AGE VERSION
ubuntu2204 Ready 2m14s v1.15.0
Or with the following command:
# microk8s.kubectl get nodes -o wide
You should see the following result:
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION
CONTAINER-RUNTIME
ubuntu2204 Ready 3m5s v1.15.0 192.168.0.2 Ubuntu 18.04 LTS 4.15.0-20-generic
containerd://1.2.5
MicroK8s comes with a lot of incorporated addons. You can enable them or disable them depending on your needs:
You can enable addons dns from the dashboard with the follwing command:
# microk8s.enable dashboard dns
You should see the following result:
Applying manifest
secret/kubernetes-dashboard-certs created
serviceaccount/kubernetes-dashboard created
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
deployment.apps/kubernetes-dashboard created
service/kubernetes-dashboard created
service/monitoring-grafana created
service/monitoring-influxdb created
service/heapster created
deployment.extensions/monitoring-influxdb-grafana-v4 created
serviceaccount/heapster created
clusterrolebinding.rbac.authorization.k8s.io/heapster created
configmap/heapster-config created
configmap/eventer-config created
deployment.extensions/heapster-v1.5.2 created
If RBAC is not enabled, Access the dashboard using the predeterminated token recovered with:
# token=$(microk8s.kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
# microk8s.kubectl -n kube-system describe secret $token
In a setup enabled for RBAC (microk8s.enable RBAC) you need to créate a user with permissions restricted s shown on
https://github.com/kubernetes/dashboard/wiki/Creating-sample-user
Enabling DNS
Applying manifest
serviceaccount/coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created
Restarting kubelet
DNS is enabled
To enable the storage extensions, do it with the following command:
# microk8s.enable storage
You should see the following result:
Enabling default storage class
deployment.extensions/hostpath-provisioner created
storageclass.storage.k8s.io/microk8s-hostpath created
Storage will be available soon
After enabling the required extensions, check the cluster information with the following command:
# microk8s.kubectl cluster-info
You should see the following result:
Kubernetes master is running at https://127.0.0.1:16443
Heapster is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Grafana is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
InfluxDB is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-influxdb:http/proxy
How to Deply Pods and Containers
You can create and deploy pods and containers with MicroK8s easily.
We'll create an Nginx deployment with the container with the following command:
# microk8s.kubectl run nginx --replicas 1 --image nginx
You should see the following result:
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed
in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create
instead.
deployment.apps/nginx created
Now you can make a list of the deployments with the following command:
# microk8s.kubectl get deployments
You should see the following result:
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 2m33s
And make a list with all the pods with the following command:
# microk8s.kubectl get pods
You should see the following result:
NAME READY STATUS RESTARTS AGE
nginx-7bb7cd8db5-n88qm 1/1 Running 0 2m47s
After the Nginx container deployment, you´ll see the Nginx service with the following command:
# microk8s.kubectl get services
You should see the following result:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.152.183.1 443/TCP 18m
nginx ClusterIP 10.152.183.127 80/TCP 45s
If you want to erase MicroK8s, first erase the Nginx deployment and service with the following command:
# microk8s.kubectl delete deployment nginx
# microk8s.kubectl delete service nginx
Then, erase MicroK8s completely from your system with the following command:
# microk8s.reset
# snap remove microk8s
Congratulations! You can now implement and manage containers with MicroK8.
Any questions? Don´t hesitate to contact us. We'll be pleased to help you out at anything you need 🙂