DTTooleras

Kubernetes for Beginners: Pods, Deployments, and Services Explained

A beginner-friendly introduction to Kubernetes — what it is, core concepts (pods, deployments, services, ingress), and how to deploy your first application.

DevToolsHub Team22 min read597 words

What is Kubernetes?

Kubernetes (K8s) is a container orchestration platform that automates deploying, scaling, and managing containerized applications. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).

Think of Kubernetes as a system that:

  • Runs your Docker containers across multiple servers
  • Restarts containers that crash
  • Scales up/down based on load
  • Routes traffic to healthy containers
  • Manages configuration and secrets

Core Concepts

Pods

A Pod is the smallest deployable unit in Kubernetes. It runs one or more containers that share networking and storage.

apiVersion: v1
kind: Pod
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  containers:
    - name: app
      image: my-app:1.0
      ports:
        - containerPort: 3000
      resources:
        requests:
          memory: "128Mi"
          cpu: "250m"
        limits:
          memory: "256Mi"
          cpu: "500m"

You rarely create Pods directly — you use Deployments instead.

Deployments

A Deployment manages a set of identical Pods, handling scaling, updates, and rollbacks.

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: my-app:1.0
          ports:
            - containerPort: 3000
          env:
            - name: NODE_ENV
              value: "production"
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: db-secret
                  key: url

This creates 3 replicas of your app. If one crashes, Kubernetes automatically creates a replacement.

Services

A Service provides a stable network endpoint for a set of Pods. Pods are ephemeral — they get new IP addresses when recreated. Services give you a consistent way to reach them.

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

Service types:

  • ClusterIP (default) — Internal only, accessible within the cluster
  • NodePort — Exposes on each node's IP at a static port
  • LoadBalancer — Creates an external load balancer (cloud providers)

Ingress

An Ingress manages external HTTP/HTTPS access to services, providing routing rules, SSL termination, and virtual hosting.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  tls:
    - hosts:
        - myapp.com
      secretName: myapp-tls
  rules:
    - host: myapp.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-app-service
                port:
                  number: 80
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80

Essential kubectl Commands

# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
kubectl get ingress

# Describe (detailed info)
kubectl describe pod my-app-xyz

# Logs
kubectl logs my-app-xyz
kubectl logs -f my-app-xyz  # follow

# Apply configuration
kubectl apply -f deployment.yaml

# Scale
kubectl scale deployment my-app --replicas=5

# Delete
kubectl delete -f deployment.yaml

# Port forward (local development)
kubectl port-forward pod/my-app-xyz 3000:3000

# Execute command in pod
kubectl exec -it my-app-xyz -- /bin/sh

ConfigMaps and Secrets

# ConfigMap for non-sensitive config
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  APP_NAME: "My App"
  LOG_LEVEL: "info"

---
# Secret for sensitive data
apiVersion: v1
kind: Secret
metadata:
  name: db-secret
type: Opaque
stringData:
  url: "postgres://user:pass@db:5432/mydb"
  api-key: "sk_live_abc123"

Getting Started

  1. Install kubectl and a local cluster (minikube, kind, or Docker Desktop)
  2. Write your Deployment YAML
  3. Apply it: kubectl apply -f deployment.yaml
  4. Expose it: kubectl apply -f service.yaml
  5. Check status: kubectl get pods

Generate Kubernetes YAML with our Kubernetes YAML Generator.

Related Tools & Tutorials

kubernetesk8skubernetes tutorialpodsdeploymentsserviceskubectlcontainer orchestration

Related articles

All articles

Practice with free tools

200+ free developer tools that run in your browser.

Browse all tools →