๐ Part 2 Mastering Kubernetes: Deploying Kind Clusters and Applications with Ease


1๏ธโฃ Overview
This section focuses on deploying a Kind (Kubernetes in Docker) cluster and deploying the EasyShop application along with MongoDB. We'll also cover networking, storage configuration, and troubleshooting.
โ
Set up a Kind Cluster (Lightweight Kubernetes in Docker)
โ
Deploy MongoDB and Persistent Storage
โ
Deploy EasyShop Application (E-Commerce app)
โ
Configure Networking, Services, and Storage
By the end of this section, youโll have a fully functional Kubernetes cluster with a running application. ๐
2๏ธโฃ Setting Up a Kind Cluster
๐น Why Use Kind?
Kind is a lightweight Kubernetes cluster that runs in Docker containers.
It allows for fast testing and local development.
It mimics a real Kubernetes cluster without requiring a cloud provider.
๐น Install Kind & Verify Installation
If you havenโt installed Kind, install it with the following:
bashCopyEditcurl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
Verify installation:
bashCopyEditkind version
โ Sample Output:
bashCopyEditkind v0.20.0 go1.19.4 linux/amd64
๐น Create a Kubernetes Cluster with Kind
We'll use a custom Kind cluster configuration to optimize networking and storage.
Download the Cluster Configuration File
bashCopyEditcurl -o kind-config.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/00-kind-config.yaml
Create the Kind Cluster
bashCopyEditkind create cluster --name easyshop --config kind-config.yaml
โ Sample Output:
bashCopyEditCreating cluster "easyshop" ...
โ Ensuring node image (kindest/node:v1.28.0) ๐ผ
โ Preparing nodes ๐ฆ
โ Configuring nodes ๐
โ Writing configuration ๐
โ Starting control-plane ๐
Cluster "easyshop" created successfully ๐
3๏ธโฃ Configuring Kubernetes Namespace
Namespaces allow logical separation of resources in a cluster.
Download & Apply the Namespace Configuration
bashCopyEditcurl -o namespace.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/01-namespace.yaml
kubectl apply -f namespace.yaml
โ Sample Output:
arduinoCopyEditnamespace/easyshop created
4๏ธโฃ Setting Up Persistent Storage for MongoDB
๐น Why is this important?
Persistent Volumes (PV) ensure MongoDB retains data across pod restarts.
Persistent Volume Claims (PVC) allow MongoDB to dynamically request storage.
๐น Create a Persistent Volume
Download & Apply the PV Configuration
bashCopyEditcurl -o mongodb-pv.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/02-mongodb-pv.yaml
kubectl apply -f mongodb-pv.yaml
โ Sample Output:
bashCopyEditpersistentvolume/mongodb-pv created
๐น Create a Persistent Volume Claim
Download & Apply the PVC Configuration
bashCopyEditcurl -o mongodb-pvc.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/03-mongodb-pvc.yaml
kubectl apply -f mongodb-pvc.yaml
โ Sample Output:
bashCopyEditpersistentvolumeclaim/mongodb-pvc created
5๏ธโฃ Creating ConfigMap and Secrets
๐น Why is this important?
ConfigMaps store non-sensitive configurations like database URIs.
Secrets store sensitive credentials securely.
๐น Create a ConfigMap
Download & Apply the ConfigMap
bashCopyEditcurl -o configmap.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/04-configmap.yaml
kubectl apply -f configmap.yaml
โ Sample Output:
arduinoCopyEditconfigmap/easyshop-config created
๐น Create a Secret
Download & Apply the Secret
bashCopyEditcurl -o secrets.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/05-secrets.yaml
kubectl apply -f secrets.yaml
โ Sample Output:
bashCopyEditsecret/mongodb-secret created
6๏ธโฃ Deploying MongoDB Service & StatefulSet
๐น Why StatefulSet?
MongoDB requires persistent identity & storage.
StatefulSets ensure pods retain their hostname and volume claims.
๐น Create MongoDB Service
Download & Apply the Service Configuration
bashCopyEditcurl -o mongodb-service.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/06-mongodb-service.yaml
kubectl apply -f mongodb-service.yaml
โ Sample Output:
bashCopyEditservice/mongodb created
๐น Deploy MongoDB StatefulSet
Download & Apply the StatefulSet
bashCopyEditcurl -o mongodb-statefulset.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/07-mongodb-statefulset.yaml
kubectl apply -f mongodb-statefulset.yaml
โ Sample Output:
bashCopyEditstatefulset.apps/mongodb created
7๏ธโฃ Deploying the EasyShop Application
๐น Download & Apply the Deployment Configuration
bashCopyEditcurl -o easyshop-deployment.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/08-easyshop-deployment.yaml
kubectl apply -f easyshop-deployment.yaml
โ Sample Output:
bashCopyEditdeployment.apps/easyshop created
๐น Deploy the EasyShop Service
bashCopyEditcurl -o easyshop-service.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/09-easyshop-service.yaml
kubectl apply -f easyshop-service.yaml
โ Sample Output:
bashCopyEditservice/easyshop created
8๏ธโฃ Verifying Deployment
๐น Check MongoDB & EasyShop Pods
bashCopyEditkubectl get pods -n easyshop
โ Expected Output:
sqlCopyEditNAME READY STATUS RESTARTS AGE
mongodb-0 1/1 Running 0 3m
easyshop-58bffd5bcd-xyz12 1/1 Running 0 2m
๐น Check Services
bashCopyEditkubectl get svc -n easyshop
โ Expected Output:
nginxCopyEditNAME TYPE CLUSTER-IP PORT(S) AGE
mongodb ClusterIP 10.96.12.10 27017/TCP 3m
easyshop ClusterIP 10.96.15.20 80/TCP 2m
๐ฏ Conclusion
๐ Kind Cluster & Application Deployment is complete!
โ
Kind Cluster is running inside Docker
โ
MongoDB is deployed with Persistent Storage
โ
EasyShop application is running on Kubernetes
Subscribe to my newsletter
Read articles from Vikas Surve directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
