Advanced Kubernetes Cluster Setup Guide
Advanced Kubernetes Cluster Setup Guide
1/59
Podman:
Run utility containers on the host machines (e.g., a log shipper
or security agent outside of Kubernetes but managed by
Ansible) using rootless Podman.
Experiment with podman generate kube to convert Podman
definitions to Kubernetes manifests.
Aqua Security:
Deep integration of Aqua CSP for runtime threat detection and
prevention within the cluster.
Scanning all deployed images for vulnerabilities and
compliance deviations.
Setting up forensics and incident response with Aqua.
Prometheus & Grafana:
Comprehensive cluster monitoring (node health, pod resources,
API server metrics).
Thanos/Prometheus Federation for long-term storage and
global view.
Advanced Alertmanager configurations with multiple receivers
and routing.
Rich Grafana dashboards for cluster health, application
performance, and security events.
Integrate with Loki (for logs) and Tempo (for traces) for full
observability.
That’s an excellent advanced DevOps project idea — ambitious, very relevant in the real world, and
a great showcase of skills across the entire DevOps stack. Let's break down the phases and
structure of this project to make it actionable.
🔧 Project Title:
"Self-Healing & Auto-Scaling Kubernetes Cluster with Advanced Security & Observability"
✅ Goals:
Provision Kubernetes cluster and infra on a cloud provider (e.g., AWS, GCP, or Azure).
🔧 Tools:
Terraform
Ansible:
🔧 Features to Implement:
Horizontal & Vertical Pod Autoscalers.
Grafana
Tempo (traces)
4/59
✅ Goals:
Use Podman to run out-of-cluster tools like log shippers, vulnerability scanners.
🔧 Use Cases:
Rootless security agent
🛡️ Integrations:
Kubernetes Admission Webhook
✅ Goals:
Deploy observability stack via Helm:
Prometheus + Thanos
Grafana dashboards
5/59
Loki (logs), Tempo (traces)
📊 Grafana Dashboards:
Node health
HPA/VPA behavior
Autoscaler in action
6/59
📹 Short walkthrough video (~3 mins)
📖 [Link] with:
Architecture Diagram
Tooling stack
Setup instructions
Provisioning: Terraform
7/59
Week Tasks
✅ Next Steps
1. Tell me your cloud provider (AWS, GCP, etc.)
Let’s start building step-by-step — I can help you generate Terraform files, Ansible roles, Helm
charts, dashboards, Aqua configuration, etc.
Perfect — we’ll adapt this to a cost-free, local-first solution using open-source tools only, and
without cloud provider lock-in like AWS/GCP/Azure.
Here’s how we’ll revise your "Self-Healing & Auto-Scaling Kubernetes Cluster with Advanced
Security & Observability" project to make it zero-cost while keeping it production-grade and fully
aligned with DevOps best practices.
8/59
Component Tool (Free & Open Source)
Tracing Tempo
Offline/Low-Bandwidth Friendly
Self-Healing Liveness & Readiness Probes, ReplicaSets, kured for reboot automation
9/59
Area Key Implementation
devops-k8s-advanced/
├── terraform/ # (Optional, for libvirt provisioning)
├── vagrant/ # Vagrant setup to bring up K8s nodes
├── ansible/ # Playbooks for provisioning and hardening
├── kubeadm/ # Kubeadm configs and scripts
├── helm-charts/
│ ├── monitoring/ # Prometheus, Grafana, Loki, etc.
│ └── demo-app/ # Custom chart with HPA, probes
├── podman/ # Host containers configs
├── security/
│ ├── trivy-scan/
│ └── admission-controllers/
├── dashboards/ # Prebuilt Grafana dashboards
├── manifests/ # K8s YAMLs not covered by Helm
└── docs/ # README, architecture diagrams, etc.
10/59
Week Goals
🛠️ First Steps
✅ Step 1: Prepare Local Environment
Install:
VirtualBox
Vagrant
Ansible
kubectl
Helm
Podman
Kubeadm
11/59
Local cluster with 3 nodes (control plane + 2 workers)?
Perfect — using a bare-metal local server (instead of VMs) keeps things simple and efficient,
especially if you have control over the hardware.
We’ll adapt the project to install and run everything directly on your physical server (e.g., a
personal PC, home lab machine, or any Linux server). This avoids virtualization overhead and aligns
with your no-cost goal.
🖥️ Assumptions:
You have one or more Linux machines (even 1 is enough to start).
Container containerd + Podman containerd for K8s, Podman for host tools
Runtime
12/59
Layer Tool Notes
devops-k8s-local/
├── ansible/ # Hardening scripts (SSH, Podman, audit)
├── kubeadm/ # Setup scripts for K8s init and join
├── helm-charts/
│ ├── monitoring/ # Prometheus, Grafana, etc.
│ └── demo-app/ # App with HPA, probes, VPA
├── podman/ # Podman-managed log/security containers
├── security/ # Trivy scans, policies, admission control
├── manifests/ # NetworkPolicies, PSS, CRDs
├── dashboards/ # Grafana dashboards
└── docs/ # Architecture, guides, screenshots
13/59
bash
bash
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
bash
2. Install containerd
bash
14/59
bash
sudo apt update && sudo apt install -y apt-transport-https ca-certificates curl
bash
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/[Link] $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f
[Link]
15/59
6. Helm Setup
bash
Prometheus stack
Grafana
Loki
Tempo
7. Podman on Host
Install Podman:
bash
Use Podman to run log shippers or monitoring agents outside the Kubernetes cluster (useful for
bare-metal).
Example:
bash
8. Security Tools
Trivy:
bash
16/59
curl -sfL [Link]
| sudo sh -s -- -b /usr/local/bin
Scan images:
bash
Resource limits/requests
bash
Integrate:
17/59
📘 Final Output
You’ll have a fully working self-healing, auto-scaling, secure Kubernetes cluster running on a bare-
metal server with:
Monitoring dashboards
Helm-managed deployments
Just say “Generate project scaffold”, and I’ll start putting it together!
Great! Let's go step-by-step in Step 1: Prepare the Host OS — assuming you're setting up a bare-
metal Kubernetes cluster on a single Linux server (Ubuntu 22.04 LTS recommended).
18/59
🛠️ Tools Needed in This Step:
Tool Purpose
19/59
🚫 3. Disable Swap (Kubernetes requires swap off)
bash
bash
free -h
20/59
EOF
bash
📋 Summary of Step 1
You’ve now:
21/59
step 2 in detail (tool , command , code )
Excellent — let’s continue with Step 2: Installing the container runtime, specifically containerd ,
which is the recommended runtime for Kubernetes.
🚀 Step-by-Step Installation
bash
containerd --version
bash
bash
toml
SystemdCgroup = false
23/59
Change it to:
toml
SystemdCgroup = true
This aligns the container runtime with the systemd cgroup driver, which is what kubelet will use
later.
bash
VERSION="v1.30.0"
curl -LO [Link]
tools/releases/download/${VERSION}/crictl-${VERSION}-[Link]
sudo tar -C /usr/local/bin -xzf crictl-${VERSION}-[Link]
rm crictl-${VERSION}-[Link]
Then test:
bash
crictl info
24/59
📋 Summary of Step 2
✅ You now have:
Installed containerd
Would you like to proceed to Step 3 in detail, or would you like a bash script to automate Step 2?
Great! You're making excellent progress. Let's move to Step 3: Installing Kubernetes core
components on your bare-metal local server.
Tool Purpose
25/59
🧱 Prerequisites
Make sure you've already completed:
📦 Step-by-Step Installation
✅ 1. Add Kubernetes apt repository
bash
bash
26/59
🔁 4. Enable kubelet to start on boot
bash
kubelet will fail to start now — that’s normal because the cluster hasn’t been bootstrapped yet. It
🧪 5. Verify installation
Check versions:
bash
kubelet --version
kubeadm version
kubectl version --client
nginx
Kubernetes v1.30.0
bash
It will likely show "inactive" or "failed" — don't worry. It becomes active after kubeadm init .
27/59
📋 Summary of Step 3
✅ You now have:
Added the official Kubernetes apt repo
Would you like me to walk you through Step 4 in detail, or generate a bash script that automates
all of Step 3?
Awesome! Now that you've installed kubeadm , kubelet , and kubectl , let's initialize your
Kubernetes cluster locally using kubeadm .
28/59
Tool Purpose
bash
swap is off:
bash
free -h
bash
This CIDR is required by Flannel (you can use others like Calico later with different CIDRs).
29/59
Configures etcd (key-value store for cluster state)
bash
📌 Save this join command — you’ll need it if you want to add more nodes later.
bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/[Link] $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
✅ Test:
bash
You should see your master/control-plane node in NotReady status — that’s expected until
networking is configured.
bash
kubectl apply -f
[Link]
bash
📋 Summary of Step 4
You now have:
31/59
✅ What’s Next?
Step 5: Install Helm & Deploy Monitoring Stack (Prometheus + Grafana)
Or
Step 6: Deploy a Demo App with HPA/Autoscaling
Would you like to proceed with Step 5: Helm Setup, or should I generate a bash script that
automates Step 4?
Great! With your Kubernetes cluster initialized, it’s time to move to:
32/59
✅ 1. Download & Install Helm
bash
Confirm installation:
bash
helm version
bash
[Link]{Version:"v3.14.x", ...}
bash
33/59
bash
✅ 2. Install Prometheus
bash
This includes:
Prometheus Operator
Prometheus
Grafana
Alertmanager
Node Exporter
bash
34/59
Default username: admin
bash
Go to “Dashboards”
Node CPU/RAM/disk
Pod/container health
📋 Summary of Step 5
You have:
35/59
✅ Installed Helm
✅ Deployed Prometheus, Grafana, and supporting services via Helm
✅ Accessed Grafana Dashboard with cluster observability
🚀 What’s Next?
Step 6: Deploy a Demo Application + Horizontal Pod Autoscaler
Would you like to continue with the demo app + HPA, or jump to advanced security setup with
Aqua & PSPs?
36/59
Tool Purpose
🧪 2. Verify installation
bash
✅ 1. Create a namespace
bash
37/59
kubectl create namespace demo
# [Link]
apiVersion: apps/v1
kind: Deployment
metadata:
name: cpu-demo
namespace: demo
spec:
replicas: 1
selector:
matchLabels:
app: cpu-demo
template:
metadata:
labels:
app: cpu-demo
spec:
containers:
- name: cpu-demo
image: vish/stress
args:
- -cpus
- "2"
resources:
requests:
cpu: 100m
limits:
cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
name: cpu-demo
namespace: demo
38/59
spec:
selector:
app: cpu-demo
ports:
- protocol: TCP
port: 80
targetPort: 8080
Apply it:
bash
bash
bash
39/59
kubectl run -n demo load-generator --image=busybox --restart=Never \
-- /bin/sh -c "while true; do wget -q -O- [Link]
done"
bash
🧹 Cleanup (Optional)
bash
📋 Summary of Step 6
✅ You now have:
Installed metrics-server
40/59
🎯 Next Steps:
Step 7: Deploy Vertical Pod Autoscaler (VPA)
Would you like to go into Step 7: VPA or dive into Step 8: Aqua Security integration?
41/59
✅ 1. Apply VPA manifests
bash
kubectl apply -f
[Link]
[Link]
kubectl apply -f
[Link]
[Link]
vpa-admission-controller
vpa-recommender
vpa-updater
✅ 1. Create a namespace
bash
42/59
✅ 2. Deploy a pod with poor resource settings
yaml
# [Link]
apiVersion: apps/v1
kind: Deployment
metadata:
name: vpa-demo
namespace: vpa-demo
spec:
replicas: 1
selector:
matchLabels:
app: vpa-demo
template:
metadata:
labels:
app: vpa-demo
spec:
containers:
- name: stress
image: vish/stress
args:
- -cpus
- "1"
resources:
requests:
cpu: "50m"
limits:
cpu: "100m"
Apply it:
bash
43/59
yaml
# [Link]
apiVersion: [Link]/v1
kind: VerticalPodAutoscaler
metadata:
name: vpa-demo
namespace: vpa-demo
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: vpa-demo
updatePolicy:
updateMode: "Auto" # Options: Off, Initial, Auto
Apply it:
bash
bash
Wait 5–10 minutes while VPA collects metrics and adjusts resources.
44/59
kubectl describe vpa vpa-demo -n vpa-demo
Look for:
yaml
Recommendations:
Container Recommendations:
Container Name: stress
Lower Bound:
Cpu: 75m
Target:
Cpu: 150m
Upper Bound:
Cpu: 300m
VPA will evict and recreate the pod with updated resource settings if updateMode: Auto .
🧹 Optional Cleanup
bash
📋 Summary of Step 7
You have:
✅ What’s Next?
45/59
Step 8: Implement Pod Security with Aqua Security or PSPs
Would you like to continue with Step 8: Aqua Security Runtime Protection next?
Here’s Step 8: Advanced Security Setup for your bare-metal Kubernetes cluster, including Trivy
vulnerability scanning, Pod Security Admission, and a runtime threat detection tool like Falco. This
will significantly strengthen your cluster’s security posture.
Pod Security Admission (PSA) Native Kubernetes admission controller enforcing Pod Security Standards
bash
46/59
trivy image nginx:latest
bash
yaml
# [Link]
apiVersion: v1
kind: Pod
metadata:
name: privileged
namespace: demo
spec:
containers:
- name: ns
47/59
image: busybox
securityContext:
privileged: true
command: ["sleep", "3600"]
bash
3. Audit logs:
bash
PSA logs the violation, helping you detect and remediate insecure pod specs [Link] +2
bash
# Install Falco
helm install falco falcosecurity/falco \
--namespace falco --create-namespace
bash
48/59
Falco uses eBPF to inspect system calls and flags suspicious activity such as:
Files
🧹 Summary of Step 8
✅ Trivy scans your images for vulnerabilities before deployment
✅ Pod Security Admission enforces secure pod specs via namespace labels
✅ Falco monitors running pods/nodes and alerts on threats
🔮 What’s Next?
Would you like to add OPA Gatekeeper or Kyverno for custom policy enforcement, or integrate
Aqua’s open‑source tools like kube-bench or kube-hunter next?
49/59
Sources
🧰 Tools Involved
Tool Purpose
Operator (Python shell script / Go controller) Watches CRDs and executes tasks
We’ll keep it simple and write a basic Bash or Python-based Operator to respond to our CRD.
50/59
# [Link]
apiVersion: [Link]/v1
kind: CustomResourceDefinition
metadata:
name: [Link]
spec:
group: [Link]
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
schedule:
type: string
target:
type: string
scope: Namespaced
names:
plural: backups
singular: backup
kind: Backup
shortNames:
- bkp
✅ Apply it
bash
51/59
yaml
# [Link]
apiVersion: [Link]/v1
kind: Backup
metadata:
name: db-backup
namespace: default
spec:
schedule: "*/10 * * * *"
target: "/data/postgres"
bash
# [Link]
from kubernetes import client, config, watch
config.load_kube_config()
crd_api = [Link]()
w = [Link]()
52/59
group="[Link]",
version="v1",
namespace="default",
plural="backups"):
backup = event['object']
name = backup['metadata']['name']
target = backup['spec']['target']
schedule = backup['spec']['schedule']
etype = event['type']
python3 [Link]
Whenever a new Backup resource is created or modified, your operator logs a simulated backup.
🧹 Cleanup (Optional)
bash
53/59
✅ Step 9 Summary
You Did Description
🔮 What’s Next?
Would you like to:
Move on to Step 10: Advanced Observability Stack (Prometheus, Loki, Grafana, Tempo)?
Let me know!
Fantastic! Let's now complete Step 10: Advanced Observability Stack using open-source tools —
Prometheus, Grafana, Loki, and Tempo — all deployed via Helm on your bare-metal Kubernetes
cluster.
54/59
Tool Purpose
🔧 Prerequisites
✅ Kubernetes cluster is running
✅ kubectl and helm are installed on your local machine
Install Helm if not already:
bash
📈 B) Deploy Prometheus
bash
55/59
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace
bash
bash
Visit: [Link]
📊 C) Deploy Grafana
Grafana is already bundled with the above Helm chart, but you can access it with:
bash
Login:
User: admin
bash
Check pods:
bash
2. Choose Loki
3. URL: [Link]
logql
{job="kubernetes"}
57/59
--namespace tracing --create-namespace
python
📋 Summary
✅ You now have a production-grade observability stack:
Component URL Purpose
58/59
🔮 Next Suggestions
Would you like to:
59/59