💡 Easiest Way to Start: This repository is configured with Devbox to instantly create a complete Kubernetes learning environment with
kind
,kubectl
,helm
, and all other tools pre-installed. Just rundevbox shell
to begin!
This repository is a hands-on playground for learning Kubernetes.
This post aims to demystify key Kubernetes concepts through practical examples. We'll use kubectl commands to interact with our local Kind Kubernetes cluster. Kubernetes, a powerful platform for orchestrating containerized applications, can be overwhelming for newcomers. In Part 1, we learned what Kubernetes is, why it matters, and explored basic concepts.
In this Part 2, we'll go through every basics to advanced Kubernetes concept one by one, with hands-on examples you can try in your own local Kind cluster. Think of this as your Kubernetes survival kit.
The only prerequisite for this tutorial is to have Devbox installed. You can install it by running the following command in your terminal:
curl -fsSL https://get.jetpack.io/devbox | bash
Once Devbox is installed, it will provide a complete, isolated environment with all the other tools you need.
With Devbox installed, you can get the entire learning environment up and running with a single command.
-
Clone this repository.
-
Run the following command in the root of the repository:
devbox shell
-
Run the
exit
when you are done:exit
This will drop you into a shell and automatically trigger the start.sh
script. This script will:
- Create a multi-node Kind cluster running Kubernetes v1.34.0.
- Install the NGINX Ingress controller.
- Install the Headlamp dashboard.
Once the script is finished, your environment is ready! It will print the login token for the Headlamp dashboard.
You can access the Headlamp dashboard at http://headlamp.localtest.me
. Copy the token from your terminal and paste it into the login screen.
When you are ready to stop, you can type exit
in your terminal to leave the Devbox shell. This will automatically trigger the cleanup process.
The repository is organized by Kubernetes concepts, with each directory containing the relevant manifests and instructions.
-
/01-cluster-setup
: Contains all the configuration for the automated environment setup. To see how the environment is created, you can inspect thestart.sh
script and the manifests in this directory. -
/02-namespaces
: Namespaces are used to create logical partitions of the cluster. Thenamespaces.yaml
file shows how to createdev
andprod
namespaces. -
/03-pods
: Pods are the smallest deployable units in Kubernetes. We have a basicnginx-pod.yaml
and apod-with-multicontainer.yaml
to show a more complex pod with shared volumes. -
/04-replicasets
: A ReplicaSet ensures that a specified number of pod replicas are running at any given time. While not often used directly, they are the basis for Deployments. Seenginx-rs.yaml
. -
/05-deployments
: Deployments are the standard way to manage stateless applications. They handle rolling updates and rollbacks. Thenginx-deploy.yaml
provides a basic example, whiledeployment-strategies.yaml
demonstrates the difference betweenRollingUpdate
andRecreate
strategies. -
/06-services
: Services provide stable network endpoints for pods. We cover four types:nginx-service-clusterip.yaml
(internal),nginx-service-nodeport.yaml
(exposes on node),nginx-service-loadbalancer.yaml
(uses cloud provider LB), andexternalname-service.yaml
(maps to an external DNS name). -
/07-configmaps-secrets
: These resources externalize configuration. We show how to create aconfigmap.yaml
andsecret.yaml
, and then how to consume them as environment variables (pod-with-env.yaml
) or as mounted files (pod-with-volume-mounts.yaml
). -
/08-volumes
: Volumes provide data persistence beyond a container's lifecycle. We show a temporarypod-with-emptydir.yaml
and a persistent example usingpvc.yaml
(the claim) andpod-with-pvc.yaml
(the consumer). -
/09-statefulsets
: For stateful applications, astatefulset.yaml
provides stable network identifiers and persistent storage. Our example uses Redis and its requiredredis-headless-service.yaml
. -
/10-daemonsets
: DaemonSets ensure that all (or some) nodes run a copy of a pod. This is useful for log collectors or monitoring agents. Seedaemonset.yaml
. -
/11-jobs-cronjobs
: For batch processing, ajob.yaml
runs a task to completion. Acronjob.yaml
runs a job on a schedule. We also include aparallel-job.yaml
to show how multiple pods can work on a task. -
/12-probes
: Probes are used for health checking. Thedeployment-with-probes.yaml
example now includeslivenessProbe
,readinessProbe
, andstartupProbe
to ensure container health. -
/13-autoscaling
: The Horizontal Pod Autoscaler (HPA) automatically scales the number of pods. See theREADME.md
in this folder for a full walkthrough using thehpa.yaml
andphp-apache-deployment.yaml
. -
/14-scheduling
: Control where your pods run.node-affinity-pod.yaml
schedules pods based on node labels,taints-and-tolerations/
forces pods to have tolerations to run on a tainted node, andpod-affinity-pod.yaml
schedules pods based on the location of other pods. -
/15-network-policies
: Network Policies control traffic flow between pods. We provide an example of allowing traffic between afrontend.yaml
and abackend.yaml
withbackend-policy.yaml
, and also adefault-deny-policy.yaml
for a more secure posture. -
/16-rbac
: Role-Based Access Control manages permissions.rbac.yaml
shows aRole
andRoleBinding
(namespaced), whileclusterrole.yaml
shows aClusterRole
andClusterRoleBinding
(cluster-wide). Other examples includepod-with-sa.yaml
andresource-quota.yaml
. -
/17-ingress
: Ingress manages external access to services, typically HTTP.ingress.yaml
shows basic host-based routing, andtls-ingress.yaml
demonstrates how to secure it with a TLS certificate. -
/18-custom-resources
: Extend the Kubernetes API by creating your own resources with acrd.yaml
(Custom Resource Definition) and then creating instances of it likefoo-resource.yaml
. -
/19-resource-requests-and-limits
: Managing resource requests and limits. -
/20-shopping-cart-app
: A complete shopping cart application.
The /20-shopping-cart-app
directory contains the Google microservices demo, a fully functional, multi-tier application that demonstrates how various Kubernetes resources work together in a realistic scenario.
Note: This application is sourced from the official GoogleCloudPlatform/microservices-demo repository.
How to Deploy:
- Make sure you are in the root of the repository.
- Apply all the manifests in the
20-shopping-cart-app
directory. This will deploy all the microservices and the Ingress to expose the application.kubectl apply -f 20-shopping-cart-app/
- Verify that all the pods are running:
kubectl get pods
How to Access:
You can now access the shopping cart application at http://shop.localtest.me
.
- Pods: The Smallest Unit
- ReplicaSets: Scaling Pods
- Deployments: The Workhorse
- Services: Networking Pods
- ConfigMaps & Secrets: External Configuration
- Namespaces: Logical Separation
- Volumes & Persistent Volumes: Data Persistence
- StatefulSets: For Stateful Apps
- DaemonSets: Node-specific Pods
- Jobs & CronJobs: Batch and Scheduled Tasks
- Probes: Health Checks
- Autoscaling: Automatic Scaling
- Node Scheduling: Controlling Pod Placement
- Network Policies: Securing Pod Communication
- RBAC, Service Accounts & Quotas: Security and Governance
- Ingress: HTTP(S) Routing
- Custom Resources & Operators: Extending Kubernetes
- Resource Requests & Limits: Managing pod resources.
- Shopping Cart App: A complete microservices demo application example.
📝 Recap We've now covered:
-
Workload objects: Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, CronJob
-
Networking: Service, Ingress, NetworkPolicy
-
Storage: Volumes, PVCs, StatefulSets
-
Configuration: ConfigMaps, Secrets, Namespaces
-
Resiliency: Probes, Autoscaling, Affinity, Taints
-
Security & Governance: RBAC, Service Accounts, Quotas
-
Extensibility: CRDs & Operators
🎯 Next Steps Practice YAMLs from this article in your own cluster. Break things intentionally - delete pods, fail readiness checks, overload CPU - and observe how Kubernetes heals itself.
After reading this two-part series, you should feel comfortable with all the core Kubernetes concepts and be ready to tackle production-grade features.
When you are finished with the tutorials, you can simply exit the Devbox shell by typing exit
.
This will automatically trigger the stop.sh
script, which deletes the Kind cluster and all its resources, leaving your system clean.