This repository explains Kubernetes concepts in a really simple way. It contains configuration files
(.yml), commands, and explanations to help you learn by doing.
##🛠 PrerequisitesBefore running the commands, ensure you have the following installed:
- Docker (The engine to run containers)
- Kind (Kubernetes in Docker - creates local clusters)
- Kubectl (The CLI tool to talk to the cluster)
##🚀 1. Cluster Management (Kind)These commands are used to create, manage, and destroy your local Kubernetes cluster.
###Create a Basic ClusterCreates a default cluster named local.
kind create cluster --name local
###Verify the ClusterCheck if the Docker container acting as the "node" is running.
docker ps
Create a Cluster with ConfigUse the provided clusters.yml to create a multi-node cluster or custom configuration.
kind create cluster --config clusters.yml --name local
###Switch Context (If needed)If you have multiple clusters, ensure kubectl is talking to the right one.
kubectl cluster-info --context kind-local
###Delete the ClusterTear down the cluster and clean up resources.
kind delete cluster --name local
2. Working with Resources (Kubectl)The primary command to create or update any resource (Pod, Deployment, Service, etc.) from a file is apply.
# General syntax
kubectl apply -f <filename>.yml
# Create a pod from file
kubectl apply -f pod.yml
# List all running pods
kubectl get pods
# List pods with more details (IP address, Node)
kubectl get pods -o wide
# View logs of a specific pod
kubectl logs <pod-name>
# Get inside the container (interactive shell)
kubectl exec -it <pod-name> -- /bin/bash
# Create replicaset
kubectl apply -f replicaset.yml
# Check the status of replicas
kubectl get replicaset
# View details (events, current replicas)
kubectl describe replicaset <replicaset-name>
# Create deployment
kubectl apply -f deployment.yml
# Watch the deployment roll out in real-time
kubectl rollout status deployment/<deployment-name>
# Update the image used in a deployment
kubectl set image deployment/<deployment-name> <container-name>=<new-image>:tag
# Undo a deployment (Rollback)
kubectl rollout undo deployment/<deployment-name>
# Create service
kubectl apply -f services.yml
# List services
kubectl get svc
# Access a service running in Kind from your local machine (Port Forwarding)
# Syntax: kubectl port-forward service/<service-name> <local-port>:<service-port>
kubectl port-forward service/my-service 8080:80
Complete Example (complete.yml)A comprehensive manifest that demonstrates a real-world setup with multiple resources working together.
This manifest includes:
- Two Deployments:
nginx-deploymentandapache-deployment(each with 2 replicas) - Two Services:
nginx-serviceandapache-service(ClusterIP type) - One Ingress:
web-apps-ingressfor routing external traffic to both services
# Deploy the complete example
kubectl apply -f complete.yml
# Check all resources created
kubectl get all
kubectl get ingress
# View the ingress details
kubectl describe ingress web-apps-ingress
# To use the Ingress, you'll need an Ingress Controller installed
# For Kind clusters, you can install the NGINX Ingress Controller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# After the controller is ready, you can access:
# - nginx service at: http://your-domain.com/nginx
# - apache service at: http://your-domain.com/apache
# (Update /etc/hosts to map your-domain.com to localhost if testing locally)# Get everything in the current namespace
kubectl get all
# Describe: The most useful command for debugging errors
# (Shows events, errors, and configuration details)
kubectl describe pod <pod-name>
kubectl describe service <service-name>
# Delete a specific resource
kubectl delete -f <filename>.yml
alias k=kubectl
# Example: k get pods