Tags
Cloud Computing, Deployment, Kubernetes, management, Minikube, ontainer orchestration, Open Source, scaling
what is kubernetes?
Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management.
what is Minikube?
Minikube is an open-source tool for local Kubernetes development and testing. It enables developers to set up a single-node Kubernetes cluster on their machines, providing a convenient and isolated environment to experiment with Kubernetes features before deploying applications in a larger context.
what is Horizontal Pod Autoscaling?
Horizontal scaling means that the response to increased load is to deploy more Pods.
Steps-1
Setup Minikube:
apt -y install docker.io
systemctl status docker
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
apt install conntrack
minikube start –vm-driver=none
minikube start –force
minikube addons enable metrics-server
kubectl top nodes
kubectl get pod,svc -n kube-system
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl top nodes
Step-2
Create kubernetes dashboard for minikube.
enable metrics-server:
minikube addons enable metrics-server
kubectl proxy –address=’0.0.0.0′ –disable-filter=true
Now check minikube dashboard
step-3
Now deploy an application in minikube
we can see bellow how to deploy a application in kubernetes.
This is the deployment yaml file to deploy a simple HTTPD application.
vi deployment01.yaml
kind: Deployment #type of manifest file
apiVersion: apps/v1 #version of deployment
metadata:
name: mydeploy
spec:
replicas: 1 #how many replica you want
selector:
matchLabels:
name: deployment
template:
metadata:
name: testpod
labels:
name: deployment
spec:
containers:
- name: demo01 #your container name
image: httpd #image name
ports:
- containerPort: 80 #port to expose container
resources:
limits:
cpu: 500m # your cpu limit
requests:
cpu: 200m #application cpu limit
apply this deployment01 yaml file
Kubectl apply -f deployment01.yaml
check your deployment
kubectl get deploy
check pods
kubectl get pods
you can check your pod metric
kubectl top pods
step-4
now apply autoscaling
kubectl autoscale deployment mydeploy –cpu-percent=20 –min=1 –max=10
#in this command if cpu utilization reached 20% autoscale will happen max scaleup limit 20 pods and min scale down pod 1
kubectl get all #this is use to see what are the things are running
kubectl get hpa #this use to see your Horizontal Pod Autoscaling
kubectl get pods –watch
step-5
open a new tab and login the pod
kubectl get pods
kubectl exec mydeploy -it — /bin/bash
apt update -y #keep updateing you can see your pods count will increase
Step-6
Rolling Updates
This type of deployment we are using in production setup to avoid downtime
vi rollingupdate.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-rolling-update
namespace: default
spec:
replicas: 4
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
role: rolling-update
spec:
containers:
- image: nginx:1.21 #change nginx version
imagePullPolicy: Always
name: nginx-container
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
---
kind: Service
apiVersion: v1
metadata:
name: service-rolling-update
labels:
app: nginx
role: rolling-update
env: prod
spec:
selector:
app: nginx
role: rolling-update
type: LoadBalancer
ports:
- protocol: TCP
port: 5000
targetPort: 80
nodePort: 31110
kubetcl apply -f rollingupdate.yaml
kubectl get deployment
kubectl get pods
minikube service service-rolling-update
kubectl describe deployment deployment-rolling-update