Getting Started with Kubernetes: A Practical Guide
Learn the fundamentals of Kubernetes, from pods and deployments to services and ingress controllers. A hands-on guide for DevOps engineers.
Getting Started with Kubernetes: A Practical Guide
Kubernetes has become the de facto standard for container orchestration. In this guide, we'll walk through the core concepts and get a basic application running on a K8s cluster.
What is Kubernetes?
Kubernetes (K8s) is an open-source platform designed to automate deploying, scaling, and operating application containers. Originally designed by Google, it is now maintained by the Cloud Native Computing Foundation (CNCF).
Core Concepts
Pods
A Pod is the smallest deployable unit in Kubernetes. It represents a single instance of a running process in your cluster.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
Deployments
A Deployment provides declarative updates for Pods and ReplicaSets. You describe a desired state, and the Deployment controller changes the actual state to the desired state.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
Services
A Service is an abstraction that defines a logical set of Pods and a policy by which to access them.
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Setting Up Your First Cluster
The easiest way to get started locally is with Minikube or kind (Kubernetes IN Docker).
# Install minikube
brew install minikube
# Start a cluster
minikube start
# Verify the cluster
kubectl cluster-info
kubectl get nodes
Deploying Your First Application
# Apply the deployment
kubectl apply -f deployment.yaml
# Check the status
kubectl get deployments
kubectl get pods
# Expose the deployment
kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80
# Access the application (minikube)
minikube service nginx-deployment
What's Next?
In the next posts, we'll cover:
- Helm charts for package management
- Ingress controllers for traffic management
- ConfigMaps and Secrets for configuration
- Horizontal Pod Autoscaling for automatic scaling
Stay tuned for more Kubernetes deep dives!