Mastering Kubernetes: How to start Part 1
How to learn and use Kubernetes?
Introduction
This article is the first step of the roadmap we need to follow to learn Kubernetes easily. The road is long indeed but it is easy to follow.
My article will help you with the very first baby steps.
Let's get us started!
We all heard about one of the biggest github project: Kubernetes!
We can find the global Github project :
We can see 64 projects through 77 repositories (on October 22th 2022)! At first, we can be a bit overwhelmed!
Don't worry, to start we just need to focus on the three following projects :
- kubernetes (the kubernetes itself)
- website (the kubernetes documentation)
- Minikube (to run the kubernetes on our local machine)
We can find the kubernetes framework on the following link:
It is a massive project with more than 562 releases (on October 22th 2022) and more than 3200 contributors:
We can find the official documentation:
This documentation is available in different languages:
But unless you don't master or like English, you will be way better off with the us english version as it will be easier to follow and understand. Translations are not always good.
Even so, the English documentation does not always sound native, it is because it is a French (like me) who wrote it!
We can see the Github Kubernetes documentation project:
Github Kubernetes documentation
How to start ?
We go to the documentation welcome page:
I would advise you to start with the two following parts:
- Understand Kubernetes (kubernetes.io/docs/concepts) : It is about the idea and theory behind Kubernetes
- Try Kubernetes (kubernetes.io/docs/tutorials): It is about how to use it in pactise.
If you are impatient and know about Kubernetes you should jump to the tutorials.
Understand Kubernetes
If you already know all the theory about Kubernetes you can skip it!
Kubernetes Concepts, Architecture and Components
Otherwise you will find here a gentle introduction about what is Kubernetes about, what problems does it solve, when does we need it: kubernetes.io/docs/concepts/overview
Then it explains the Kubernetes architecture and components: kubernetes.io/docs/concepts/overview/compon..
Communication with Kubernetes through the API
This part explains us how we can communicate with the Kubernetes cluster through the API: directly through the REST API or through the tool Kubectl.
We will use Kubectl most of the time. The REST API can be useful when we need to create application which monitors the Kubernetes cluster for example.
See the link kubernetes.io/docs/concepts/overview/kubern..
Most operations can be performed through the kubectl command-line interface or other command-line tools, such as kubeadm, which in turn use the API. However, you can also access the API directly using REST calls.
At last but not least, we need to understand all the main objects with which we need to work: kubernetes.io/docs/concepts/overview/workin..
It is the biggest part of the theory and you need to read it completely. It is well written so it is worth it!
Basically there are two way of working with the Kubernetes objects. We need to know them: kubernetes.io/docs/concepts/overview/workin..:
- imperative way: where we tell exactly Kubernetes API what we want to creatre
- declarative way: where we express Kubernetes API our desire and Kubernetes API will decide itself how to reconcile the ideal status we want and the real cluster status.
We will work 95% of the time with the second management technique: Declarative way through the use of files and/or directories.
I really advice you to look at the link kubernetes.io/docs/concepts and focus on:
- Cluster architecture
- Containers
- Workloads
- Services, Load Balancing, and Networking
Then when you read them all, you can read the other parts.
- Storage
- Configuration
At last you can read the other parts which are more focused. You will need them once you mastered the other parts.
You must understand the following workflow:
Ingress => Service => Pod => Container
Try Kubernetes with Minikube
The article will use Minikube on Windows 11. But it is very easy to follow on Mac or Linux too.
First the official doc is there: minikube.sigs.k8s.io/docs
Once you have a clear idea about what is Kubernetes, what is the architecture and what it can be used, we will see together how to create one our dev machine a simple Kubernetes cluster made of one single node.
It will be more than enough for our dev needs.
I advice to look at: kubernetes.io/docs/tutorials/hello-minikube
We will use the Minikube here on Windows but it is very easy to use on Mac and Linux too!
You have the choice here:
- we can test minikube with the website online with remote env
- we can install minikube locally.
If you use the website you follow the instructions online directly on the web page which provides a virtual environment remotely, we get:
It is very convenient to start with, but i would advise you to get minikube on your local machine instead, that way we can work in a real situation on your local dev machine. Moreover we can enjoy the very last version of minikube and kubernetes!
We will show you how to do this now.
You can find in my previous article all the details we need to install the lastest Minikube version and how to run with one node (now we can run with multi nodes) and how to install Dashboard github.com/kubernetes/dashboard and metrics server github.com/kubernetes-sigs/metrics-server
Please go to the link:
nicolasbarlatier.hashnode.dev/net-core-tip-..
I will remind here the main steps:
- go the download page: minikube.sigs.k8s.io/docs/start
- download the minikube executable
First we need to check if your OS can handle the Virtualisation.
All you need to do is:
>systeminfo
Host Name: xxx
OS Name: Microsoft Windows 10 Professionnel
OS Version: 10.0.19043 N/A Build 19043
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Multiprocessor Free
Registered Owner: N/A
Registered Organization: N/A
Product ID: xxx
Original Install Date: 08/10/2020, 10:38:13
System Boot Time: 23/10/2022, 13:39:25
System Manufacturer: xxxx
System Model: xxx
System Type: x64-based PC
.......
Hyper-V Requirements: VM Monitor Mode Extensions: Yes
Virtualization Enabled In Firmware: Yes
Second Level Address Translation: Yes
Data Execution Prevention Available: Yes
All you need to check is the Hyper-V requirements sections. If you see "Yes" on every line it means our OS can handle the Virtualisation!
You can also read instructions on the link: kubernetes.io/fr/docs/tasks/tools/install-m..
It is in French, curiously not in English but it is not hard to understand, here is the translation :)
To check if virtualization is supported on Windows 8 and above, run the following command on your Windows terminal or command prompt.
systeminfo
If you get the following output, virtualization is supported on Windows.
Hyper-V Requirements: VM Monitor Mode Extensions: Yes Virtualization Enabled In Firmware: Yes Second Level Address Translation: Yes Data Execution Prevention Available: Yes
If you see the following output, your system already has a hypervisor installed and you can skip the next step.
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
To enable the Hyper-V you can read:
learn.microsoft.com/fr-fr/virtualization/hy..
It works on Windows 10 Enterprise, Pro, or Education.
After you will see the line
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
Then we can install Minikube with the installer.
github.com/kubernetes/minikube/releases/dow..
Then we only need to run the installer once it is done we only need to start Minikube!
First let's see all the commands we can use:
λ minikube help
minikube provisions and manages local Kubernetes clusters optimized for development workflows.
Basic Commands:
start Starts a local Kubernetes cluster
status Gets the status of a local Kubernetes cluster
stop Stops a running local Kubernetes cluster
delete Deletes a local Kubernetes cluster
dashboard Access the Kubernetes dashboard running within the minikube cluster
pause pause Kubernetes
unpause unpause Kubernetes
Images Commands:
docker-env Provides instructions to point your terminal's docker-cli to the Docker Engine inside minikube.
(Useful for building docker images directly inside minikube)
podman-env Configure environment to use minikube's Podman service
cache Manage cache for images
image Manage images
Configuration and Management Commands:
addons Enable or disable a minikube addon
config Modify persistent configuration values
profile Get or list the current profiles (clusters)
update-context Update kubeconfig in case of an IP or port change
Networking and Connectivity Commands:
service Returns a URL to connect to a service
tunnel Connect to LoadBalancer services
Advanced Commands:
mount Mounts the specified directory into minikube
ssh Log into the minikube environment (for debugging)
kubectl Run a kubectl binary matching the cluster version
node Add, remove, or list additional nodes
cp Copy the specified file into minikube
Troubleshooting Commands:
ssh-key Retrieve the ssh identity key path of the specified node
ssh-host Retrieve the ssh host key of the specified node
ip Retrieves the IP address of the specified node
logs Returns logs to debug a local Kubernetes cluster
update-check Print current and latest version number
version Print the version of minikube
options Show a list of global command-line options (applies to all commands).
Other Commands:
completion Generate command completion for a shell
Use "minikube <command> --help" for more information about a given command.
Let's check the status:
λ minikube status
E1023 16:21:26.497163 13088 status.go:258] status error: host: state: unknown state "minikube": docker container inspect minikube --format={{.State.Status}}: exit status 1
stdout:
stderr:
error during connect: This error may indicate that the docker daemon is not running.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/minikube/json": open //./pipe/docker_engine: The system cannot find the file specified.
E1023 16:21:26.498788 13088 status.go:261] The "minikube" host does not exist!
minikube
type: Control Plane
host: Nonexistent
kubelet: Nonexistent
apiserver: Nonexistent
kubeconfig: Nonexistent
As you can see minikube uses the docker behind the scenes. But we don't have docker installed and started (the docker daemon is not running)
We need first to install docker desktop and start it.
Like it is said:
If minikube fails to start, see the drivers page for help setting up a compatible container or virtual-machine manager.
Let's install Docker Desktop : docs.docker.com/desktop/install/windows-ins..
After we can start Docker Desktop:
Once Docker Daemon started we get:
λ minikube status
minikube
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped
We can start Minikube with the default driver: docker
λ minikube start
* minikube v1.27.0 on Microsoft Windows 10 Pro 10.0.19043 Build 19043
* Kubernetes 1.25.0 is now available. If you would like to upgrade, specify: --kubernetes-version=v1.25.0
* Using the docker driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* Restarting existing docker container for "minikube" ...
* Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
- kubelet.housekeeping-interval=10s
* Verifying Kubernetes components...
- Using image k8s.gcr.io/metrics-server/metrics-server:v0.6.1
- Using image docker.io/kubernetesui/dashboard:v2.6.0
- Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
- Using image gcr.io/k8s-minikube/storage-provisioner:v5
* Enabled addons: metrics-server, storage-provisioner, dashboard, default-storageclass
! C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\kubectl.exe is version 1.21.9-dispatcher, which may have incompatibilites with Kubernetes 1.23.3.
- Want kubectl v1.23.3? Try 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
We are ready! We have already Kubectl installed and configured to communicate with the minikube cluster of one node.
λ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
We can enable two add-ons:
- dashboard
- metrics server
λ minikube addons enable metrics-server
λ minikube addons enable dashboard
At the end we get the following add-ons list:
λ minikube addons list
|-----------------------------|----------|--------------|--------------------------------|
| ADDON NAME | PROFILE | STATUS | MAINTAINER |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador | minikube | disabled | 3rd party (Ambassador) |
| auto-pause | minikube | disabled | Google |
| csi-hostpath-driver | minikube | disabled | Kubernetes |
| dashboard | minikube | enabled ✅ | Kubernetes |
| default-storageclass | minikube | enabled ✅ | Kubernetes |
| efk | minikube | disabled | 3rd party (Elastic) |
| freshpod | minikube | disabled | Google |
| gcp-auth | minikube | disabled | Google |
| gvisor | minikube | disabled | Google |
| headlamp | minikube | disabled | 3rd party (kinvolk.io) |
| helm-tiller | minikube | disabled | 3rd party (Helm) |
| inaccel | minikube | disabled | 3rd party (InAccel |
| | | | [info@inaccel.com]) |
| ingress | minikube | disabled | Kubernetes |
| ingress-dns | minikube | disabled | Google |
| istio | minikube | disabled | 3rd party (Istio) |
| istio-provisioner | minikube | disabled | 3rd party (Istio) |
| kong | minikube | disabled | 3rd party (Kong HQ) |
| kubevirt | minikube | disabled | 3rd party (KubeVirt) |
| logviewer | minikube | disabled | 3rd party (unknown) |
| metallb | minikube | disabled | 3rd party (MetalLB) |
| metrics-server | minikube | enabled ✅ | Kubernetes |
| nvidia-driver-installer | minikube | disabled | Google |
| nvidia-gpu-device-plugin | minikube | disabled | 3rd party (Nvidia) |
| olm | minikube | disabled | 3rd party (Operator Framework) |
| pod-security-policy | minikube | disabled | 3rd party (unknown) |
| portainer | minikube | disabled | 3rd party (Portainer.io) |
| registry | minikube | disabled | Google |
| registry-aliases | minikube | disabled | 3rd party (unknown) |
| registry-creds | minikube | disabled | 3rd party (UPMC Enterprises) |
| storage-provisioner | minikube | enabled ✅ | Google |
| storage-provisioner-gluster | minikube | disabled | 3rd party (Gluster) |
| volumesnapshots | minikube | disabled | Kubernetes |
|-----------------------------|----------|--------------|--------------------------------|
Let's check our cluster with Dashboard:
λ minikube dashboard
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
* Opening http://127.0.0.1:64302/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
Let's check "All Namespaces" and we can check we can see all the objects like the pods and their resource (memory, cpu) usage graphs from the metrics server!
Let's check our local kubectl is configured to use the minikube node:
λ kubectl config current-context
minikube
Let's check we have one single node:
λ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 3d22h v1.23.3
At last let's get all the resources of all the namespaces of our node:
λ kubectl get all --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system pod/coredns-64897985d-gkv6m 1/1 Running 1 (15m ago) 3d22h
kube-system pod/etcd-minikube 1/1 Running 1 (15m ago) 3d22h
kube-system pod/kube-apiserver-minikube 1/1 Running 1 (15m ago) 3d22h
kube-system pod/kube-controller-manager-minikube 1/1 Running 1 (15m ago) 3d22h
kube-system pod/kube-proxy-4pd2l 1/1 Running 1 (15m ago) 3d22h
kube-system pod/kube-scheduler-minikube 1/1 Running 1 (15m ago) 3d22h
kube-system pod/metrics-server-7c57dd9c77-cgvdw 1/1 Running 1 (15m ago) 3d22h
kube-system pod/storage-provisioner 1/1 Running 3 (14m ago) 3d22h
kubernetes-dashboard pod/dashboard-metrics-scraper-57d8d5b8b8-mwpkq 1/1 Running 1 (15m ago) 3d22h
kubernetes-dashboard pod/kubernetes-dashboard-56b9bdfcc8-mxff9 1/1 Running 2 (14m ago) 3d22h
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d22h
kube-system service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 3d22h
kube-system service/metrics-server ClusterIP 10.97.230.30 <none> 443/TCP 3d22h
kubernetes-dashboard service/dashboard-metrics-scraper ClusterIP 10.102.27.249 <none> 8000/TCP 3d22h
kubernetes-dashboard service/kubernetes-dashboard ClusterIP 10.96.113.145 <none> 80/TCP 3d22h
NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
kube-system daemonset.apps/kube-proxy 1 1 1 1 1 kubernetes.io/os=linux 3d22h
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system deployment.apps/coredns 1/1 1 1 3d22h
kube-system deployment.apps/metrics-server 1/1 1 1 3d22h
kubernetes-dashboard deployment.apps/dashboard-metrics-scraper 1/1 1 1 3d22h
kubernetes-dashboard deployment.apps/kubernetes-dashboard 1/1 1 1 3d22h
NAMESPACE NAME DESIRED CURRENT READY AGE
kube-system replicaset.apps/coredns-64897985d 1 1 1 3d22h
kube-system replicaset.apps/metrics-server-7c57dd9c77 1 1 1 3d22h
kubernetes-dashboard replicaset.apps/dashboard-metrics-scraper-57d8d5b8b8 1 1 1 3d22h
kubernetes-dashboard replicaset.apps/kubernetes-dashboard-56b9bdfcc8 1 1 1 3d22h
We are not ready to work with Kubernetes on our local machine.
Conclusion
It is the first step of our roadmap to learn Kubernetes. I hope it was useful and if you liked it please subscribe and give it a clap :) Thanks again for having read the article !