GoDasturchi
kubectl in Practice

kubectl in Practice

Amalda kubectl

Agar manifest — me'morning chizmasi bo'lsa, kubectl — quruvchi bilan gaplashadigan RADIO: siz shu orqali klasterga buyruq berasiz ("shu chizmani qur") va klasterning JORIY holatini so'raysiz ("hozir nima bo'layapti?"). kubectl — Kubernetes klasteri bilan ishlashning ASOSIY, kundalik vositasi.

terminal
$ kubectl apply -f deployment.yaml
deployment.apps/web created
service/web created

$ kubectl get pods -n production
NAME                   READY   STATUS    RESTARTS   AGE
web-7d9f8c6b5d-2xk4p   1/1     Running   0          12s
web-7d9f8c6b5d-9mjqz   1/1     Running   0          12s
web-7d9f8c6b5d-vh3rt   1/1     Running   0          12s

$ kubectl get deployments -n production
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    3/3     3            3           14s

kubectl apply -f deployment.yaml — "Writing a Real Kubernetes Manifest" darsida yozgan faylni klasterga YUBORADI: Kubernetes uni o'qib, ichidagi Deployment va Serviceni YARATADI. kubectl get pods esa — "ReplicaSet: Keeping N Copies Running" darsida yozgan Reconcile mantig'i ISHLAB, replicas: 3 talabiga javoban UCHTA Pod yaratganini KO'RSATADI. Pod nomlaridagi tasodifiy suffiks (-2xk4p) — aynan sizning NewReplicaSetdagi nextID hisoblagichingizning, real Kubernetes'dagi ko'rinishi.

terminal
$ kubectl describe pod web-7d9f8c6b5d-2xk4p -n production
Name:         web-7d9f8c6b5d-2xk4p
Namespace:    production
Status:       Running
IP:           10.244.1.7
Containers:
  app:
    Image:          myapp:v2.1.0
    State:          Running
    Ready:          True
    Liveness:       http-get http://:8080/health delay=0s timeout=1s period=10s
    Readiness:      http-get http://:8080/ready delay=0s timeout=1s period=10s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  15s   default-scheduler  Successfully assigned production/web-7d9f8c6b5d-2xk4p to node-2
  Normal  Pulled     14s   kubelet            Container image "myapp:v2.1.0" already present on machine
  Normal  Started    13s   kubelet            Started container app

$ kubectl logs web-7d9f8c6b5d-2xk4p -n production
2024/01/15 10:23:01 server started on :8080
2024/01/15 10:23:05 GET /ready 200

$ kubectl scale deployment web --replicas=5 -n production
deployment.apps/web scaled

kubectl describe pod — bitta Pod haqida BATAFSIL ma'lumot: qaysi Node'ga joylashtirilgani ("The Scheduler: Placing Pods on Nodes" darsidagi Schedule natijasi), va pastdagi Events bo'limi — aynan Scheduler va kubelet BAJARGAN qadamlarning JURNALI. kubectl logs — konteynerning stdout/stderr chiqishini ko'rsatadi ("Logging with slog" kursida yozgan loglaringiz aynan shu yerda ko'rinadi). kubectl scale --replicas=5 — "Horizontal Pod Autoscaling" darsida o'zingiz yozgan ScaleTo metodini, QO'LDA, terminal orqali chaqirishning ekvivalenti.

Key Takeaway

Key Takeaway:

kubectl — manifest'larni klasterga yuborish (apply), joriy holatni ko'rish (get, describe, logs) va o'zgartirish (scale) uchun ishlatiladigan asosiy buyruq qatori vositasi; uning har bir buyrug'i ortida, aynan shu kursda o'zingiz Go'da qurgan Pod, ReplicaSet, Scheduler mantig'i ishlaydi.

NEXT UP

StatefulSets vs Deployments

kubectl in Practice

Amalda kubectl

Agar manifest — me'morning chizmasi bo'lsa, kubectl — quruvchi bilan gaplashadigan RADIO: siz shu orqali klasterga buyruq berasiz ("shu chizmani qur") va klasterning JORIY holatini so'raysiz ("hozir nima bo'layapti?"). kubectl — Kubernetes klasteri bilan ishlashning ASOSIY, kundalik vositasi.

terminal
$ kubectl apply -f deployment.yaml
deployment.apps/web created
service/web created

$ kubectl get pods -n production
NAME                   READY   STATUS    RESTARTS   AGE
web-7d9f8c6b5d-2xk4p   1/1     Running   0          12s
web-7d9f8c6b5d-9mjqz   1/1     Running   0          12s
web-7d9f8c6b5d-vh3rt   1/1     Running   0          12s

$ kubectl get deployments -n production
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    3/3     3            3           14s

kubectl apply -f deployment.yaml — "Writing a Real Kubernetes Manifest" darsida yozgan faylni klasterga YUBORADI: Kubernetes uni o'qib, ichidagi Deployment va Serviceni YARATADI. kubectl get pods esa — "ReplicaSet: Keeping N Copies Running" darsida yozgan Reconcile mantig'i ISHLAB, replicas: 3 talabiga javoban UCHTA Pod yaratganini KO'RSATADI. Pod nomlaridagi tasodifiy suffiks (-2xk4p) — aynan sizning NewReplicaSetdagi nextID hisoblagichingizning, real Kubernetes'dagi ko'rinishi.

terminal
$ kubectl describe pod web-7d9f8c6b5d-2xk4p -n production
Name:         web-7d9f8c6b5d-2xk4p
Namespace:    production
Status:       Running
IP:           10.244.1.7
Containers:
  app:
    Image:          myapp:v2.1.0
    State:          Running
    Ready:          True
    Liveness:       http-get http://:8080/health delay=0s timeout=1s period=10s
    Readiness:      http-get http://:8080/ready delay=0s timeout=1s period=10s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  15s   default-scheduler  Successfully assigned production/web-7d9f8c6b5d-2xk4p to node-2
  Normal  Pulled     14s   kubelet            Container image "myapp:v2.1.0" already present on machine
  Normal  Started    13s   kubelet            Started container app

$ kubectl logs web-7d9f8c6b5d-2xk4p -n production
2024/01/15 10:23:01 server started on :8080
2024/01/15 10:23:05 GET /ready 200

$ kubectl scale deployment web --replicas=5 -n production
deployment.apps/web scaled

kubectl describe pod — bitta Pod haqida BATAFSIL ma'lumot: qaysi Node'ga joylashtirilgani ("The Scheduler: Placing Pods on Nodes" darsidagi Schedule natijasi), va pastdagi Events bo'limi — aynan Scheduler va kubelet BAJARGAN qadamlarning JURNALI. kubectl logs — konteynerning stdout/stderr chiqishini ko'rsatadi ("Logging with slog" kursida yozgan loglaringiz aynan shu yerda ko'rinadi). kubectl scale --replicas=5 — "Horizontal Pod Autoscaling" darsida o'zingiz yozgan ScaleTo metodini, QO'LDA, terminal orqali chaqirishning ekvivalenti.

Key Takeaway

Key Takeaway:

kubectl — manifest'larni klasterga yuborish (apply), joriy holatni ko'rish (get, describe, logs) va o'zgartirish (scale) uchun ishlatiladigan asosiy buyruq qatori vositasi; uning har bir buyrug'i ortida, aynan shu kursda o'zingiz Go'da qurgan Pod, ReplicaSet, Scheduler mantig'i ishlaydi.

NEXT UP

StatefulSets vs Deployments