k8s-labs-developer

🛠️ Übung: Kubernetes Pod mit hostPath Volume


🎯 Ziel


📁 Schritt 1: hostPath-Pod YAML erstellen

Erstelle die Datei hostpath-pod.yaml mit folgendem Inhalt:

apiVersion: v1
kind: Pod
metadata:
  name: hostpath-demo
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command: ["sleep", "3600"]
    volumeMounts:
    - mountPath: /data
      name: my-volume
  volumes:
  - name: my-volume
    hostPath:
      path: /tmp/hostdata
      type: DirectoryOrCreate

Erläuterung:


📁 Schritt 2: Pod anwenden

kubectl apply -f hostpath-pod.yaml

📁 Schritt 3: In den Container einsteigen

kubectl exec -it hostpath-demo -- bash

Dann im Container:

echo "Hello from inside the container" > /data/test.txt
exit

📁 Schritt 4: Auf dem Host (Node) prüfen

Voraussetzung: Du kannst auf den Node zugreifen (z. B. bei minikube oder kind möglich)

minikube ssh
cat /tmp/hostdata/test.txt

Du solltest sehen:

Hello from inside the container

📁 Schritt 5: Clean-up

kubectl delete pod hostpath-demo

Optional: Auf dem Host den Ordner löschen

minikube ssh
sudo rm -rf /tmp/hostdata