Thuta Learning
ရှာဖွေရန်
BasicDevOpsintermediate

kubectl Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • kubectl Basics ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် kubectl command/YAML ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

kubectl (ကျယ်ကျယ်ကြားရင် 'kube-control' or 'kube-cuttle' လို့ ဖတ်ကြပါတယ်) က Control Plane ရဲ့ API Server ကို HTTP request ပို့ပြီး cluster ကို ထိန်းချုပ်ပေးတဲ့ command line tool ပါ — resource တွေကို get/create/update/delete လုပ်လို့ရပါတယ်။ Command pattern က `kubectl <verb> <resource-type> <resource-name>` ဆိုတဲ့ ပုံစံအတိုင်း လိုက်ပါတယ် — ဥပမာ `kubectl get pods` ဆိုတာ 'pod အားလုံးကို ပြပါ' လို့ ဆိုလိုတာပါ။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

`kubectl get nodes` နဲ့ cluster ထဲက node တွေကို list ကြည့်လို့ရပါတယ်။ `kubectl get pods` နဲ့ pod တွေကို ကြည့်လို့ရပါတယ် (ပထမတစ်ခါ run ရင် empty ဖြစ်နေမှာပါ — pod ဘာမှ create မထားသေးလို့ပါ)။ `kubectl describe <resource>` က resource တစ်ခုချင်းစီရဲ့ detail (event log, error message ပါ) ကို ပြပေးပါတယ် — debugging လုပ်တဲ့အခါ အကူအညီအများဆုံး command ပါ။

အတူတူ ကြည့်မယ်

bash
# See cluster nodes
kubectl get nodes

# See all pods in the current namespace
kubectl get pods

# See pods with more detail (IP, node, status)
kubectl get pods -o wide

# See detailed info + events for one pod
kubectl describe pod <pod-name>

# Check kubectl can talk to your cluster
kubectl cluster-info
You should see
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   5m    v1.29.0

၅ မိနစ် စမ်းကြည့်

`kubectl get nodes` နဲ့ `kubectl cluster-info` ကို local cluster ပေါ်မှာ run ကြည့်ပြီး output ကို ကိုယ့်ဘာသာ ဖတ်ရှင်းကြည့်ပါ။

သတိလေးတစ်ချက်

kubectl command တွေက default ဖြင့် current context (ချိတ်ဆက်ထားတဲ့ cluster) ပေါ်မှာသာ အလုပ်လုပ်ပါတယ် — production cluster နဲ့ local cluster ကို context ရောပြီး command မှားမပို့မိအောင် `kubectl config current-context` နဲ့ အမြဲ စစ်ပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `kubectl get pods` run လိုက်ပြီး empty result ရလို့ 'error ဖြစ်နေတယ်' ထင်ခြင်း — pod ဘာမှ create မထားရင် empty ဖြစ်ခြင်းက ပုံမှန်ပါ
  • kubectl ရဲ့ output ကို ဖတ်ရှုချသွားပြီး `describe` command ကို လုံးဝ မသုံးဘဲ error ဖြေရှင်းရန် ကြိုးစားခြင်း

အခု ကိုယ်တိုင် စမ်းကြည့်

`kubectl get nodes` နဲ့ `kubectl cluster-info` ကို local cluster ပေါ်မှာ run ကြည့်ပြီး output ကို ကိုယ့်ဘာသာ ဖတ်ရှင်းကြည့်ပါ။

You'll know it worked when: NAME STATUS ROLES AGE VERSION minikube Ready control-plane 5m v1.29.0

kubectl Basics | Thuta Learning