Kubernetes#
Sources
Hello minikube tutorial on official k8s site.
kubernetes crashcourse video on youtube.
Setup#
Here’s everything you need to install to start experimenting with Kubernetes on your local machine.
Minicube#
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. Read more in start with minikube page. This is a tool that we’ll use to play with kubernetes.
You need to install it and use the command to start it:
!minikube start &> /dev/null
Once you’ve completed the previous command, you’ll have a corresponding container called minikube
in your docker. The following cell shows it.
!docker ps | grep minikube
a29d82ecba5e gcr.io/k8s-minikube/kicbase:v0.0.44 "/usr/local/bin/entr…" 29 seconds ago Up 28 seconds 127.0.0.1:32787->22/tcp, 127.0.0.1:32786->2376/tcp, 127.0.0.1:32785->5000/tcp, 127.0.0.1:32784->8443/tcp, 127.0.0.1:32783->32443/tcp minikube
To make sure everything is OK, try checking the minikube status.
!minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
You can refresh everything by stopping and deleting the minikube
container.
!minikube delete
🔥 Deleting "minikube" in docker ...
🔥 Deleting container "minikube" ...
🔥 Removing /home/f.kobak@maxbit.local/.minikube/machines/minikube ...
💀 Removed all traces of the "minikube" cluster.
kubectl#
kubectl
is a command line interface that allows you to interact with Kubernetes, in particular with Kubernetes started with minikube
. Check the installation guide.
For me, using the ubunty option snap install kubectl --classic
worked well.
!kubectl version --client
Client Version: v1.29.5
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Core components#
Here we will discuss components of the kubernetes:
Pod is a group of containers.
Deployment is an abstraction that manages pods.
Service is pod that was exposed.
Creating hello-node
deployment.
!kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.39 -- /agnhost netexec --http-port=8080
deployment.apps/hello-node created
Now we can access the deployments list:
!kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
hello-node 1/1 1 1 51s
It have a pod that can be listed using the appropriate command:
!kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-node-55fdcd95bf-v9w97 1/1 Running 0 2m18s
Now we only have a basic service that runs on k8s.
!kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5m17s
But after exposing hello-node
we’ll have one more service.
%%bash
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
kubectl get services
Error from server (AlreadyExists): services "hello-node" already exists
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node LoadBalancer 10.97.143.213 <pending> 8080:32657/TCP 90s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7m57s