All Resources
Guide
KubernetesDevOpsCloud
June 9, 2024

Kubernetes Deployment Guide

Deploy and manage applications in Kubernetes with deployments, services, and ingress.

Overview

Kubernetes orchestrates containerized applications at scale. Learn to deploy, scale, and manage applications with Kubernetes objects.

Core Concepts

  • Pods: Smallest deployable unit
  • Deployments: Manage pod replicas
  • Services: Network access to pods
  • Ingress: HTTP routing
  • ConfigMaps/Secrets: Configuration management

Basic Deployment

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web
        image: myapp:1.0.0
        ports:
        - containerPort: 3000
        env:
        - name: PORT
          value: "3000"

Expose with Service

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

Ingress Configuration

# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-app-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-app-service
            port:
              number: 80

Common Commands

# Apply configuration
kubectl apply -f deployment.yaml

# Check deployment status
kubectl get deployments
kubectl describe deployment web-app

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

# View logs
kubectl logs -f deployment/web-app

# Port forward for testing
kubectl port-forward service/web-app-service 8080:80

Kubernetes can automatically scale applications based on CPU and memory usage.

Curated by

Shyam