Kubernetes basic concepts and practice
- Introduction
Automatic deployment of the containerized applications across different servers.
Distribution of the load across multiple servers
Auto-scaling of the deployment applications
Monitoring and health check of the containers
Self-healing: Replacement of the failed containers
Types of supported container runtimes:
DOCKER
CRI-O
CONTAINERD
POD: is the smallest unit in the K8S
K8S Cluster
K8B Service
Cluster management
Install software
Minikube: can create K8S cluster with single node in a local PC
Virtual machine or container manager: Virtualbox, VMware, Docker, Hyper-V, Parallels
Install kubectl
To start minikube:
minikube start
Install Visual studio Code
install K8S extension
Docker extension
Go ahead to create a cluster, pod...
Check status of the cluster
minikube status
Start cluster
minikube start --driver=virtualbox
Check IP address
minikube ip
Connect to cluster
ssh docker@<IP>
use password tcuser
show container
docke ps
exit
then check cluster info
(base) system@b15:~$ k cluster-info
Kubernetes control plane is running at https://192.168.59.100:8443
CoreDNS is running at https://192.168.59.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
(base) system@b15:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 15d v1.23.3
Get pods information
(base) system@b15:~$ k get pods
NAME READY STATUS RESTARTS AGE
k8s-web-hello-576fbc864d-gtnk4 1/1 Running 0 3h51m
k8s-web-hello-576fbc864d-pfh88 1/1 Running 0 3h51m
k8s-web-hello-576fbc864d-tzzn7 1/1 Running 0 3h51m
k8s-web-hello-576fbc864d-v6lvv 1/1 Running 0 3h51m
Run a pod from the nginx image
kubectl run nginx --image=nginx
This will download the image from the docker hub to run a pod
Get information of the pod
k describe pod nginx
connect to the pod
ssh docker@<IP>
doker ps
connect to the container
docker exec -it <name> sh
hostname
check ip of the container
hostname -i
run the service web server
curl ip of the container
delete the pod
k delete pod nginx
Deploy the service
k create deployment nginx-deployment --image=nginx
k get deployments
k get pods
get information of the deployment
k describe deployment nginx-deployment
scaling the pod into 4 replicas
k scale deployment nginx-deployment --replicas=4
get IP of pods
k get pod -o wide
ssh to the pod when we are inside the node
minikube ip
ssh docker@<ip>
#to access the pod
curl ip
Connect to a deployment
expose the port
k expose deployment nginx-deployment --port=8080 --target-port=80
k get services
curl 10.108.156.147:8080
ssh docker@ip node
curl 10.108.156.147:8080
k describe nginx-deployment