To install microk8s, run
sudo snap install microk8s --classic
Enable rules in firewall
sudo ufw allow in on cni0 sudo ufw allow out on cni0 sudo ufw default allow routed
Enable addons
microk8s enable dns dashboard storage
To see status of current addons, run
microk8s status
Here is status for a defaul install
root@ip-172-26-0-217:~# microk8s status microk8s is running high-availability: no datastore master nodes: 127.0.0.1:19001 datastore standby nodes: none addons: enabled: ha-cluster # Configure high availability on the current node disabled: ambassador # Ambassador API Gateway and Ingress cilium # SDN, fast with full network policy dashboard # The Kubernetes dashboard dns # CoreDNS fluentd # Elasticsearch-Fluentd-Kibana logging and monitoring gpu # Automatic enablement of Nvidia CUDA helm # Helm 2 - the package manager for Kubernetes helm3 # Helm 3 - Kubernetes package manager host-access # Allow Pods connecting to Host services smoothly ingress # Ingress controller for external access istio # Core Istio service mesh services jaeger # Kubernetes Jaeger operator with its simple config keda # Kubernetes-based Event Driven Autoscaling knative # The Knative framework on Kubernetes. kubeflow # Kubeflow for easy ML deployments linkerd # Linkerd is a service mesh for Kubernetes and other frameworks metallb # Loadbalancer for your Kubernetes cluster metrics-server # K8s Metrics Server for API access to service metrics multus # Multus CNI enables attaching multiple network interfaces to pods portainer # Portainer UI for your Kubernetes cluster prometheus # Prometheus operator for monitoring and logging rbac # Role-Based Access Control for authorisation registry # Private image registry exposed on localhost:32000 storage # Storage class; allocates storage from host directory traefik # traefik Ingress controller for external access root@ip-172-26-0-217:~#
To see all pods/services/deploymens, run
microk8s kubectl get all --all-namespaces
To avoid typing microk8s before kubectl, run
alias kubectl="microk8s kubectl"
You can add this to .bashrc to make it permanent.
To run an nginx container
root@ip-172-26-0-217:~# microk8s kubectl create deployment nginx --image=nginx:latest deployment.apps/nginx created root@ip-172-26-0-217:~# microk8s kubectl get pods NAME READY STATUS RESTARTS AGE nginx-55649fd747-xngk5 1/1 Running 0 106s root@ip-172-26-0-217:~#
To expose the nginx deployment to public, run
kubectl expose deployment nginx --port 80 --target-port 80 --type ClusterIP --name nginx --external-ip 172.26.0.217
Here –external-ip 172.26.0.217 is IP of the node. In this case, it is internal IP of Amazon ec2 sevrer (eth0 IP).
The above expose command create a service
root@ip-172-26-0-217:~# kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.152.183.1443/TCP 45m nginx ClusterIP 10.152.183.11 172.26.0.217 80/TCP 8s root@ip-172-26-0-217:~#
To undo the expose command, you need to delete the service with name nginx.
root@ip-172-26-0-217:~# kubectl delete services nginx service "nginx" deleted root@ip-172-26-0-217:~#
See Kubernetes
Leave a Reply