Lektion 4: Dein erster Pod

Erstelle und verwalte deinen ersten Kubernetes Pod

20 min

Was ist ein Pod?

Ein Pod ist die kleinste deploybare Einheit in Kubernetes. Er enthält einen oder mehrere Container, die sich Storage und Netzwerk teilen.

Pod erstellen

Imperativ (schnell zum Testen)

BASH
kubectl run nginx --image=nginx --port=80
Click to expand and view more

Deklarativ (empfohlen für Produktion)

Erstelle eine Datei my-first-pod.yaml:

YAML
apiVersion: v1
kind: Pod
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
Click to expand and view more

Anwenden mit:

BASH
kubectl apply -f my-first-pod.yaml
Click to expand and view more

Pods verwalten

BASH
# Alle Pods anzeigen
kubectl get pods

# Pod-Details anzeigen
kubectl describe pod my-nginx

# Logs ansehen
kubectl logs my-nginx

# In Pod einsteigen
kubectl exec -it my-nginx -- /bin/bash

# Pod löschen
kubectl delete pod my-nginx
Click to expand and view more

Pod-Lebenszyklus

PLAINTEXT
Pending → Running → Succeeded/Failed
 Unknown (bei Kommunikationsproblemen)
Click to expand and view more

Praktische Übung

  1. Erstelle einen Pod mit dem nginx Image
  2. Prüfe den Status mit kubectl get pods -w
  3. Zeige die Logs an
  4. Verbinde dich zum Pod und prüfe, ob nginx läuft
  5. Lösche den Pod wieder

Nächste Lektion: Deployments verstehen

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut