All posts
KubernetesDevOpsCloud

Kubernetes Basics: From Zero to Your First Deployment

A beginner-friendly walkthrough of core Kubernetes concepts — Pods, Deployments, and Services — with real YAML examples.

March 15, 20262 min read

Kubernetes Basics: From Zero to Your First Deployment

Kubernetes (K8s) is the industry-standard container orchestration platform. It's intimidating at first, but the core concepts are straightforward once you see them in action.

Core Concepts

ConceptWhat It Does
PodThe smallest deployable unit — wraps one or more containers
DeploymentManages replicas of a Pod and handles rolling updates
ServiceStable network endpoint to reach your Pods
NamespaceVirtual cluster for isolating resources

Your First Pod

apiVersion: v1
kind: Pod
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  containers:
    - name: app
      image: node:20-alpine
      ports:
        - containerPort: 3000

Apply it:

kubectl apply -f pod.yaml
kubectl get pods

Using a Deployment (Recommended)

Never run bare Pods in production. Use a Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: myrepo/my-app:latest
          ports:
            - containerPort: 3000
          env:
            - name: NODE_ENV
              value: "production"

Exposing with a Service

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 3000
  type: LoadBalancer

Essential kubectl Commands

# Apply any manifest
kubectl apply -f deployment.yaml

# Watch pods start up
kubectl get pods -w

# Check logs
kubectl logs deployment/my-app

# Exec into a container
kubectl exec -it <pod-name> -- /bin/sh

# Delete everything
kubectl delete -f deployment.yaml

Next Steps

  • Learn Helm for packaging Kubernetes apps
  • Set up Horizontal Pod Autoscaler for automatic scaling
  • Explore Ingress controllers for routing external traffic

Kubernetes has a steep learning curve but understanding Deployments and Services alone gets you 80% of the way there for most applications.