Skip to main content
โšก Calmops

Kubernetes: Orchestration Basics

Kubernetes: Orchestration Basics

Kubernetes orchestrates containerized applications at scale. This article covers Kubernetes fundamentals.

Introduction

Kubernetes provides:

  • Container orchestration
  • Auto-scaling
  • Self-healing
  • Rolling updates
  • Service discovery

Kubernetes Manifests

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: app
        image: myapp:1.0.0
        ports:
        - containerPort: 3000
        env:
        - name: NODE_ENV
          value: "production"
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 10

Service

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

Commands

Kubectl Commands

# โœ… Good: Deploy application
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

# โœ… Good: Check status
kubectl get deployments
kubectl get pods
kubectl get services

# โœ… Good: View logs
kubectl logs deployment/app-deployment
kubectl logs pod-name

# โœ… Good: Scale deployment
kubectl scale deployment app-deployment --replicas=5

# โœ… Good: Update image
kubectl set image deployment/app-deployment app=myapp:2.0.0

# โœ… Good: Rollback
kubectl rollout undo deployment/app-deployment

# โœ… Good: Delete resources
kubectl delete deployment app-deployment
kubectl delete service app-service

Best Practices

  1. Use resource limits:

    # โœ… Good: Resource limits
    resources:
      requests:
        memory: "256Mi"
        cpu: "250m"
      limits:
        memory: "512Mi"
        cpu: "500m"
    
    # โŒ Bad: No limits
    
  2. Use health checks:

    # โœ… Good: Health checks
    livenessProbe:
      httpGet:
        path: /health
        port: 3000
      initialDelaySeconds: 30
    
    # โŒ Bad: No health checks
    
  3. Use namespaces:

    # โœ… Good: Use namespaces
    kubectl create namespace production
    kubectl apply -f deployment.yaml -n production
    
    # โŒ Bad: Use default namespace
    kubectl apply -f deployment.yaml
    

Summary

Kubernetes is essential. Key takeaways:

  • Create deployments
  • Define services
  • Set resource limits
  • Use health checks
  • Scale applications
  • Update images
  • Rollback deployments
  • Use namespaces

Next Steps

Comments