Pod

Pod erőforás dokumentáció megjelenítése

# kubectl explain pod

Egyszerű pod létrehozása egy konténerrel parancssorból

# kubectl run nginx-pod --image=registry.r-l.hu/library/nginx:latest --restart=Never

Egyszerű pod létrehozása egy konténerrel yaml fájlból

# cat > egyszeru-pod-egy-kontenerrel.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: registry.r-l.hu/library/nginx:latest
EOF

Konténer indítása

# kubectl apply -f egyszeru-pod-egy-kontenerrel.yaml
pod/nginx-pod created
# kubectl wait --for=condition=Ready pod/nginx-pod --timeout=90s
pod/nginx-pod condition met

Konténer ellenőrzése

# kubectl get pod/nginx-pod -o yaml

# kubectl describe pod/nginx-pod
Name: nginx-pod
Namespace: default
Priority: 0
Service Account: default
Node: worker01.r-logic.eu/185.207.251.233
Start Time: Tue, 16 Sep 2025 04:33:07 +0200
Labels: run=nginx-pod
Annotations: <none>
Status: Running
IP: 10.244.1.14
IPs:
IP: 10.244.1.14
Containers:
nginx-pod:
Container ID: containerd://406b1f5856e2bfaa9e91d391078458c56e64c2f9d068f9b65dbab4d3c0b44e8b
Image: registry.r-l.hu/library/nginx:latest
Image ID: registry.r-l.hu/library/nginx@sha256:d5f28ef21aabddd098f3dbc21fe5b7a7d7a184720bc07da0b6c9b9820e97f25e
Port: <none>
Host Port: <none>
State: Running
Started: Tue, 16 Sep 2025 04:33:14 +0200
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-f79p9 (ro)
Conditions:
Type Status
PodReadyToStartContainers True
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-f79p9:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
Optional: false
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 53s default-scheduler Successfully assigned default/nginx-pod to worker01.r-logic.eu
Normal Pulling 52s kubelet Pulling image "registry.r-l.hu/library/nginx:latest"
Normal Pulled 46s kubelet Successfully pulled image "registry.r-l.hu/library/nginx:latest" in 5.622s (5.622s including waiting). Image size: 72319182 bytes.
Normal Created 46s kubelet Created container: nginx-pod
Normal Started 46s kubelet Started container nginx-pod

Konténer nevének kiolvasása

# kubectl get pod/nginx-pod -o jsonpath='{.spec.containers[*].name}'

Utasítások futtatása a konténerben

# kubectl exec -it pod/nginx-pod -c nginx -- sh

Naplók megtekintése

# kubectl logs pod/nginx-pod
# kubectl logs pod/nginx-pod -c nginx

Port tesztelése

# kubectl port-forward pod/nginx-pod 8080:80

Egyszer használatos pod tesztelésekhez

# kubectl run debug-pod --rm -it --image=registry.r-l.hu/library/busybox:1.36 --restart=Never -- sh

Deployment

Létrehozás

Deployment létrehozása parancssorból

# kubectl create deployment nginx-deployment --image=registry.r-l.hu/library/nginx:latest && kubectl wait --for=condition=Available deployment/nginx-deployment --timeout=90s
deployment.apps/nginx-deployment created
deployment.apps/nginx-deployment condition met

Deployment példányok módosítása

Frissítés és visszaállás

Deployment definíció

cat > nginx-deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
kubernetes.io/change-cause: "Initial deploy: nginx 1.25"
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: registry.r-l.hu/library/nginx:1.25
ports:
- containerPort: 80
EOF
kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created

Frissítés 1.26-ra

# kubectl annotate deployment/nginx-deployment kubernetes.io/change-cause="Upgrade to nginx 1.26" --overwrite
deployment.apps/nginx-deployment annotated
# kubectl set image deployment/nginx-deployment nginx=registry.r-l.hu/library/nginx:1.26
deployment.apps/nginx-deployment image updated
# kubectl rollout status deployment/nginx-deployment
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
deployment "nginx-deployment" successfully rolled out
# kubectl rollout history deployment/nginx-deployment
deployment.apps/nginx-deployment
REVISION CHANGE-CAUSE
1 Upgrade to nginx 1.26
2 Upgrade to nginx 1.26

Frissítés 1.27-re

# kubectl rollout pause deployment/nginx-deployment
# kubectl annotate deployment/nginx-deployment kubernetes.io/change-cause="Upgrade to nginx 1.27" --overwrite
deployment.apps/nginx-deployment annotated
# kubectl set image deployment/nginx-deployment nginx=registry.r-l.hu/library/nginx:1.27
deployment.apps/nginx-deployment image updated
# kubectl rollout resume deployment/nginx-deployment
# kubectl rollout status deployment/nginx-deployment
Waiting for deployment "nginx-deployment" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
deployment "nginx-deployment" successfully rolled out
kubectl rollout history deployment/nginx-deployment
deployment.apps/nginx-deployment
REVISION CHANGE-CAUSE
1 Upgrade to nginx 1.26
2 Upgrade to nginx 1.27
3 Upgrade to nginx 1.27
kubectl get replicasets -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
nginx-deployment-6585597c84 0 0 0 6m35s nginx registry.r-l.hu/library/nginx:1.26 app=nginx,pod-template-hash=6585597c84
nginx-deployment-6ccb84987c 3 3 3 2m58s nginx registry.r-l.hu/library/nginx:1.27 app=nginx,pod-template-hash=6ccb84987c
nginx-deployment-7bdc5996d7 0 0 0 7m27s nginx registry.r-l.hu/library/nginx:1.25 app=nginx,pod-template-hash=7bdc5996d7

Visszaállás korábbi verzióra

# kubectl rollout undo deployment/nginx-deployment
deployment.apps/nginx-deployment rolled back
# kubectl get replicasets -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
nginx-deployment-6585597c84 3 3 3 12m nginx registry.r-l.hu/library/nginx:1.26 app=nginx,pod-template-hash=6585597c84
nginx-deployment-6ccb84987c 0 1 1 8m33s nginx registry.r-l.hu/library/nginx:1.27 app=nginx,pod-template-hash=6ccb84987c
nginx-deployment-7bdc5996d7 0 0 0 13m nginx registry.r-l.hu/library/nginx:1.25 app=nginx,pod-template-hash=7bdc5996d7