🚀 Kubernetes Project Flow Explained for Beginners

 By Raees Qazi | DevOps Engineer | Learner | Mentor | Creator

🌐 What Are We Doing?

In today’s practical, we’re going to understand and implement a basic Kubernetes project. Here’s a simple flow of how our project will work:

Namespace → Pod (via Deployment) → Environment Data via ConfigMap & Secret → Storage using PV & PVC

Before jumping into commands, let’s quickly grasp the concepts that make this work.

Press enter or click to view image in full size

🔐 ConfigMap & Secret — What’s the Difference?

When deploying applications like MySQL, we often need to pass sensitive and non-sensitive environment variables — like database names or passwords. But hardcoding them in the deployment file is a security risk.

That’s where ConfigMap and Secret come in.

✅ ConfigMap — For Non-Sensitive Data

  • Stores data in plain text as key: value.
  • Ideal for things like DB name, host, etc.

Helps us avoid hardcoding values directly into the deployment file.

kind: ConfigMap
apiVersion: v1
metadata:
name: mysql-config
namespace: mysql
labels:
app: todo
data:
MYSQL_DB: "todo-db"

Once defined, this ConfigMap will be automatically read by the deployment file.

🔒 Secret — For Sensitive Data

  • Stores sensitive data like passwords.
  • Data is Base64-encoded (not encrypted, just obfuscated).
  • Used to securely pass credentials.
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
namespace: mysql
type: Opaque
data:
password: dHJhaW53aXRoc2h1YmhhbQ==

Both ConfigMap and Secret help us decouple configuration data from the application code.

💾 Persistent Volume (PV) vs Persistent Volume Claim (PVC)

When we run databases like MySQL in Kubernetes, data persistence is crucial. Otherwise, all data is lost if the pod restarts.

Here’s how it works:

📁 PV — Persistent Volume

  • It’s the actual storage provisioned by the cluster from the host machine.
  • Example: Host has 20 GB, cluster uses 10 GB → This 10 GB is PV.

📦 PVC — Persistent Volume Claim

  • It’s the request made by pods to use a specific portion of PV.
  • Example: Pod requests 2 GB from the PV → This is a PVC.

Quick Note:
You might see G (Gigabyte) and Gi (Gibibyte).

  • 1G = 1000 MB
  • 1Gi = 1024 MiB ≈ 1074 MB

🧪 Let’s Start the Practical!

We’ll use a ready-to-use repo to deploy MySQL with all the above components.

🔗 Clone the Repo

git clone https://github.com/Raeesqazi/kubestarter
cd kubestarter/example/mysql

🔐 Create and Apply Secret

echo "trainwithshubham" | base64   # Encode your MySQL root password
kubectl create namespace mysql
kubectl apply -f secrets.yml

Set your working context to the new namespace:

kubectl config set-context --current --namespace=mysql
kubectl get secret # Confirm the secret is created

📄 Apply ConfigMap

kubectl apply -f configMap.yml

💽 Apply Persistent Volume

kubectl apply -f persistentVols.yml
kubectl get pv # Check if PV is created

🚀 Deploy MySQL

kubectl apply -f deployment.yml
kubectl describe deployment mysql
kubectl get pods

🧠 Access the Pod and Verify MySQL

kubectl exec -it <Pod-Name> -- /bin/bash
mysql -u root -p
# Enter the password (decoded one)
SHOW DATABASES;

🎉 You should see your todo-db database created!

🤝 Final Thoughts

This exercise introduces key Kubernetes concepts in a hands-on way:

  • Namespace: Isolates resources.
  • ConfigMap & Secret: Manage environment configurations securely.
  • PV & PVC: Ensure data persistence.
  • Deployment: Manages pod replicas.

If you found this blog helpful, feel free to share it with others in the DevOps community. Let’s grow and learn together. 💡


Raees Qazi
DevOps Engineer | Learner | Mentor | Creator

Comments

Popular posts from this blog

📘 Understanding Prometheus in a Simple Way-Part 3 (For DevOps Beginners)

Grafana Setup & Dashboard Creation (Part-5)— Explained by Raees Yaqoob Qazi

My First Python Program: A Simple Calculator