-
Notifications
You must be signed in to change notification settings - Fork 8
Ubuntu k8s
How to quickly setup Kubernetes under Ubuntu.
Required OS:
- Ubuntu 20 LTS Tested:
- Ubuntu 20.04.3 LTS
TIP: See:
- https://gitlab.com/hpaluch/mysql-micro-k8s for example how to setup WordPress+MySQL with OpenEBS replicated volumes
- https://gitlab.com/hpaluch/openebs-to-pdf how to print OpenEBS site documentation to PDF
At first you have to install snapd
packages using:
(see a bit unhelpful https://snapcraft.io/docs/installing-snap-on-ubuntu)
sudo apt-get install snapd
WARNING! There also exists package snap
which has nothing
common with snapcraft (it is some kind of DNA tool :-)
Now we have to follow guide from:
sudo snap install microk8s --classic
microk8s status --wait-ready
You will likely get permission error and will be guided how to fix it:
sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
Now relogin (you can use newgrp microk8s
instead, but
it will invoke new shell)
After relogin try:
microk8s status --wait-ready
# we changed plugint list a bit
microk8s enable dashboard dns rbac
Normally you have to run kubectl
using microk8s
wrapper:
(from guide)
microk8s kubectl get all --all-namespaces
NOTE: you can ignore the messages from dashboard (about RBAC). To get token you just need to run:
microk8s dashboard-proxy
It will print Dashboard URL and necessary token
What next - you can follow for example:
Example from above guide:
microk8s kubectl create deployment nginx --image=nginx
Now you have to wait until command below will
show Status: Running
and READY: 1/
:
microk8s kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kc7zq 1/1 Running 0 59s
How to reach Nginx Pod? According to official docs
- https://v1-19.docs.kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
- There many ways, we will use
- NodePort So we can follow:
- https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/ Do this:
- get deployment name:
microk8s kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE nginx 1/1 1 1 30m
- so we have verified that our deployment is called
nginx
- we can expose it via service
nginx-svc
:kubectl expose deployment nginx \ --type=NodePort --name=nginx-svc --port=80
- now you have to list what port was exposed using:
microk8s kubectl get svc nginx-svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-svc NodePort 10.152.183.88 <none> 80:32001/TCP 109s
- in our case you have to use exposed port 32001, for example:
curl http://127.0.0.1:32001
- above port 32001 should be reachable also from any remote
host using url like
http://IP_OF_YOUR_K8S:32001
(ensure that your firewall is not blocking it)
Once you are finished with k8s you should stop it to relieve your computer resources:
microk8s stop
- Use Ingress plugin to expose services
- Add node to cluster:
- Learn from Google's k8s examples:
- Learn Helm:
- Learn Helm from Bitnami charts:
Resources:
Copyright © Henryk Paluch. All rights reserved.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License