Pod هو الوحدة الذرية في Kubernetes — حاوية أو أكثر تتشارك namespace الشبكة والتخزين. نادرًا ما تنشر Pod مجردًا في الإنتاج، لكن فهمه الأساس.
المتطلبات المسبقة
- عنقود يعمل — k3s.
kubectlمكوّن.
الخطوة 1: الأمر الأمر — شغّل شيئًا
kubectl run nginx --image=nginx:1.27-alpine --restart=Never
kubectl get pods
kubectl get pod nginx -o wide
kubectl wait --for=condition=Ready pod/nginx --timeout=60s
الخطوة 2: تصريحي — اكتب YAML
pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.27-alpine
ports:
- containerPort: 80
resources:
requests: { cpu: 50m, memory: 64Mi }
limits: { cpu: 200m, memory: 128Mi }
readinessProbe:
httpGet: { path: /, port: 80 }
initialDelaySeconds: 2
periodSeconds: 5
livenessProbe:
httpGet: { path: /, port: 80 }
initialDelaySeconds: 10
periodSeconds: 10
kubectl apply -f pod.yaml
kubectl describe pod web | tail -20
الخطوة 3: الوصول إلى Pod
kubectl port-forward pod/web 8080:80 &
curl http://localhost:8080/
kubectl exec -it web -- sh
kubectl logs web -f
الخطوة 4: Init Containers و Sidecars
spec:
initContainers:
- name: wait-for-db
image: busybox:1.36
command: ['sh', '-c', 'until nc -z db 5432; do sleep 2; done']
containers:
- name: app
image: skyline/api:1.0
- name: log-shipper
image: skyline/log-shipper:1.0
الخطوة 5: دورة الحياة و restartPolicy
ثلاث قيم: Always، OnFailure، Never.
kubectl get pods -w
الخطوة 6: الحذف
kubectl delete pod web
kubectl delete -f pod.yaml
التحقق
kubectl get pods
kubectl get events --sort-by=.lastTimestamp | tail -20
kubectl top pod
الخاتمة
Pod هو أصغر وحدة تنشرها. معرفة كتابته وقراءة أحداثه وسجلاته أساس Deployments و StatefulSets.
Comments
0 total · 0 threads