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

Vikas SurveVikas Surve
4 min read

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

๐Ÿ“Œ Next Step: Kubernetes Dashboard

0
Subscribe to my newsletter

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

Written by

Vikas Surve
Vikas Surve