Kubernetes Cluster Maintenance

Ankit KumarAnkit Kumar
2 min read

Upgrading the cluster->

As I am using minikube that is local Kubernetes cluster, so firstly we will upgrade minikube-

1. Upgrade MiniKube binary:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube /usr/local/bin/

Check upgrade-

minikube version

2. Upgrading Kubernetes cluster in minikube->

Starting minikube with desired version- put you desired version

minikube start --kubernetes-version=v1.28.0

Update minikube add-on-

minikube addons list
minikube addons enable <addon-name>

Check node and pod functionality-

kubectl get nodes
kubectl get pods --all-namespaces

Backing-up and restoring data->

While using MiniKube on AWS EC2 instance, is crucial for disaster recovery and maintaining integrity of the application.

1. Back up strategies->

a. Back up of Kubernetes Resources:

Using kubectl to export resources: Exporting the configuration for resource into YAML file

kubectl get all --all-namespaces -o yaml > all-resources-backup.yaml

b. Backup of etcd:

Backup the data directory: etcd stores the state of whole Kubernetes cluster.

sudo ETCDCTL_API=3 etcdctl snapshot save snapshot.db

c. Backing up application data:

If the application is using database(mysql, mongodb etc.), ensure the database is backed-up

Using native database backup tool:

mysqldump -u username -p database_name > backup.sql

Volume Snapshot: For Persistent volume using aws EBS. Run the code and restart the data directory.

aws ec2 create-snapshot --volume-id <volume-id> --description "Volume snapshot"

Restoring Strategies->

a. Restoring Kubernetes Resources: Applying backup YAML to restore the resources.

kubectl apply -f all-resources-backup.yaml

b. Restore etcd with snapshot:

sudo ETCDCTL_API=3 etcdctl snapshot restore snapshot.db --data-dir=/var/lib/etcd

c. Restore application database:

Using database-specific tool for backing up:

mysql -u username -p database_name < backup.sql

Scaling Cluster->

1. Scaling in minikube: Minikube is for local development and testing, so the resources are limited, we can still adjust resources allocated to the minikube VM.

a. scaling CPU, memory in minikube:

minikube stop
minikube start --cpus=<number_of_cpus> --memory=<memory_in_mb>

Example:

minikube start --cpus=4 --memory=8192

b. Add Nodes:

minikube start --nodes=<number_of_nodes> --cpus=2 --memory=4096

c. Horizontal Pod Autoscaling (HPA):

kubectl autoscale deployment <deployment-name> --cpu-percent=50 --min=1 --max=10

check status:

kubectl get hpa

0
Subscribe to my newsletter

Read articles from Ankit Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ankit Kumar
Ankit Kumar