A comprehensive, hands-on repository documenting the journey of mastering Kubernetes using KOPS (Kubernetes Operations). This repository bridges the gap between basic container orchestration and production-ready cluster management on AWS.
This project demonstrates a real-world DevOps workflow for deploying and managing a Kubernetes cluster. It covers everything from setting up a management server to complex networking concepts like Pod IP isolation.
- Infrastructure as Code: Managing AWS clusters via KOPS manifests.
- Cluster Lifecycle: Dry-runs, updates, and zero-downtime scaling.
- Deep Dive: In-depth exploration of Namespaces, Pod types, and Control Plane internals.
- Real-time Production Concepts: Leveraging Auto Scaling Groups for high availability.
Before diving into Kubernetes, we need to prepare our Management Server (Ubuntu 24.04 recommended).
We use a dedicated EC2 instance (t3.medium) to manage the cluster. No direct login to the nodes is required—everything is handled from here.
- IAM Role: Attach an IAM role with
AdministratorAccessto the Management Server. - SSH Keys: Generate keys specifically for the cluster.
ssh-keygen
Install kubectl and kops to the system path:
# Install KOPS
wget https://github.com/kubernetes/kops/releases/download/v1.34.0/kops-linux-amd64
chmod +x kops-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops
# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectlBoost productivity by adding aliases and environment variables to your ~/.bashrc:
# Environment Variables
export NAME=example-cluster.com
export KOPS_STATE_STORE=s3://my-k8s-state-bucket
export AWS_REGION=us-east-1
export CLUSTER_NAME=example-cluster.com
# Shortcuts
alias ku='kubectl'
# Apply changes
source ~/.bashrcKOPS is the best tool for deploying production-grade clusters on AWS because it automatically configures Auto Scaling Groups (ASG). If a node fails or is deleted, the ASG will instantly recreate it.
-
Dry Run Manifest Generation:
kops create cluster --name=${NAME} \ --state=${KOPS_STATE_STORE} --zones=us-east-1a,us-east-1b \ --node-count=2 --control-plane-count=1 --node-size=t3.medium \ --control-plane-size=t3.medium --ssh-public-key ~/.ssh/id_ed25519.pub \ --dns-zone=${NAME} --dry-run --output yaml > cluster.yml
-
Manifest Customization: Modify
cluster.ymlto adjust subnet CIDRs for better isolation:- Subnet A:
172.20.1.0/24 - Subnet B:
172.20.2.0/24
- Subnet A:
-
Deploy & Validate:
kops create -f cluster.yml kops update cluster --name ${NAME} --yes --admin kops validate cluster --wait 10m
A healthy cluster should report:
1 Master Node2 Worker Nodes
ku get nodes # List all nodes
ku cluster-info # Check cluster status
ku get ns # List namespacesNamespaces allow multiple teams (e.g., Alpha, Bravo, Charlie) to work on the same cluster without interference.
- Tip: Communication between namespaces can be restricted or allowed using Network Policies.
A Pod is the smallest deployable unit. It can contain:
- Single Container: One app, one container.
- Multi-Container: Main app + Sidecar (logs) or Proxy (networking).
| Feature | Imperative | Declarative |
|---|---|---|
| Command | ku run testpod1 --image=nginx |
ku apply -f pod.yaml |
| Pros | Quick, good for testing | Reproducible, version controlled |
| Real-time Tip | Use --dry-run=client -o yaml to generate manifests quickly. |
In realtime, I sometimes use an inline YAML method directly from the terminal:
echo '
apiVersion: v1
kind: Pod
metadata:
labels:
run: testpod3
name: testpod3
spec:
containers:
- image: nginx:latest
name: testpod3
' | ku apply -f -
Inspect the brain of your cluster in the kube-system namespace:
ku get pods -n kube-system -o wide | grep -E 'api|etcd|scheduler|controller'Observation: All control plane components run on the same private IP address of the Master Node, ensuring low latency and tight integration.
.
├── cluster.yml # KOPS cluster configuration
├── manifests/ # Kubernetes YAML declarations
│ └── testpod1.yml # Sample Nginx Pod
├── scripts/ # Setup and utility scripts
└── README.md # You are here!
This repository serves as a blueprint for anyone transitioning from local K8s experimentation to cloud-native cluster management. By combining the power of KOPS with structured kubectl operations, we achieve a scalable and resilient infrastructure.
Happy Architecting! 🚀