Clusters as Cattle

Workshop ( Part-2 )

Clusters as Cattle

Clusters as Cattle ဆိုသည်မှာ kubernetes cluster တစ်ခုမှ တစ်ခြားသော kubernetes clusters များကို kubernetes ၏ အသေးဆုံး unit ဖြစ်သော pod များ ကဲ့သို့ လိုအပ်ရင် လိုအပ်သလို create, scale, upgrade, destroy အလွယ်တကူ ပြုလုပ်ခြင်းဖြစ်သည်။

Cluster API

Kubernetes project တစ်ခုဖြစ်သည့် Cluster API သည် declarative ပုံစံ Kubernetes style APIs ဖြင့် kubernetes မှ တစ်ခြားသော kubernetes cluster များကို သက်ဆိုင်ရာ provider များတွင် creation, configuration, and management စသည်တို့ကို ပြုလုပ်ပေးသည်။

Kind to AWS

ဒီ Scenario တွင် Local ( laptop သို့မဟုတ် Desktop ) ထဲမှ Kind ဖြင့် kubernetes cluster တစ်ခုတည်ဆောက်ပြီး Cluster API ကို အသုံးပြု၍ AWS cloud provider နှင့် integration ပြုလုပ်မည်ဖြစ်သည်။ ထို့နောက် local k8s cluster မှ နောက်ထပ် kubernetes clusters များကို AWS EC2 ပေါ်တွင် လိုချင်သလောက် တည်ဆောက်သွားမှာ ဖြစ်သည်။

Workshop Prerequisite

Install aws cli in Linux

Install clusterawsadm in Linux

ပထမဆုံး clusterawsadm ကိုအသုံးပြုပြီး AWS IAM ထဲတွင် policy များ role များ စသည့် လိုအပ်ချက်များကို bootstrap လုပ်ပေးရမှာ ဖြစ်ပါသည်။ clusterawsadm သည် အလွယ်ပြောရရင် aws cloud provider API များကိုအသုံးပြုပြီး cluster တည်ဆောက်ရန်အတွက် automation ပြုလုပ်ပေးထားသည့် golang ဖြင့် ရေးထားသည့် client binary tool တစ်ခု ဖြစ်သည်။ clusterawsadm နှင့် လုပ်ပေးနိုင်သည့် feature များကို ဖေါ် ပြပေးပါမည်။

Kubernetes Cluster API Provider AWS

Feature

  • Native Kubernetes manifests and API

  • Manages the bootstrapping of VPCs, gateways, security groups and instances.

  • Choice of Linux distribution between Amazon Linux 2, CentOS 7 and Ubuntu 18.04, using pre-baked AMIs.

  • Deploys Kubernetes control planes into private subnets with a separate bastion server.

  • Doesn't use SSH for bootstrapping nodes.

  • Installs only the minimal components to bootstrap a control plane and workers.

  • Currently supports control planes on EC2 instances.

AWS ကို access လုပ်ရန် လိုအပ်သည့် environment variables များကို ကြေညာရမည်။

AWS EC2 instance အတွက် local user ၏ ssh key pair မှ public key ကို upload လုပ်ပေးရမည်။

Workshop part-1 တွင် kind ဖြင့် cluster တည်ဆောက်ပြီးပါက ထပ်မံတည်ဆောက်ရန် မလိုအပ်ပါ။

လိုအပ်သည့် manifest များကို Kubernetes User Group Myanmar git repo မှ clone ရပါမည်။

Cluster API ကို အောက်ဖော်ပြပါ command ဖြင့် install ပြုလုပ်ရပါမယ်။

AWS ပေါ်တွင် အသစ်ပြုလုပ်မည့် kubernetes-cluster ကို bootstrap ပြုလုပ်ရန် လိုအပ်သည့် cloud init script များကို generate ထုတ်ရန် Cluster API ရဲ့ component တစ်ခုဖြစ်တဲ့ bootstrap-components ကို ထည့်သွင်းပေးရပါမယ်။

infrastructure provision ပြုလုပ်ရန်လိုအပ်သည့် AWS resources များကို ယူသုံးရန် infrastructure-components များကိုလည်း ထည့်သွင်းပေးရပါမည်။

local k8s cluster တွင် အပေါ်မှ ထည့်သွင်းခဲ့သည့် components ၃ ခု running ဖြစ်သွားလျှင် local k8s cluster နှင့် aws ကို integration ပြုလုပ်ပြီး ဖြစ်ပါသည်။

AWS အပေါ်တွင် cluster တည်ဆောက်မည်ဖြစ်သဖြင့် CRD ဖြစ်တဲ့ AWSCluster resource နှင့် Cluster resource ၂ မျိုးကို တည်ဆောက်ပေးရပါမည်။ name တွင် ကိုယ်လိုချင်သည့် နာမည်ပေးနိုင်သည်။ region တွင် အပေါ်တွင် export လုပ်ခဲ့သော Env variable မှ AWS_REGION တန်ဖိုးကို ပြောင်းလဲထားပေးရပါမည်။ sshKeyName တွင် ရှေ့တွင် aws အပေါ်သို့ upload လုပ်ပေးခဲ့သော key pair name ဖြစ်ရပါမည်။

တည်ဆောက်ခဲ့သော kubernetes cluster များကို kubectl get clusters ဖြင့် တွေ့ရပါလိမ့်မယ်။ PHASE section တွင် provisioning ဖြစ်နေပါလိမ့်မည်။ AWS အပေါ်တွင် create လုပ်သော cluster မရောက်သေးပါ။

ပုံမှန် cluster setup လုပ်သည့်အတိုင်း control-plane နှင့် worker node များကို setup လုပ်ရန် ကျန်ရှိသေးသည်။ kubernetes ၏ Machine resource နှင့် AWSMachine resource ကိုအသုံးပြုကာ Cluster ၏ control-plane object ကို တည်ဆောက်ရမည်။ ရှေ့ကအတိုင်း sshKeyName များကို ပြန်ထည့်ရန်လိုအပ်ပါသည်။

control-plane object ကို တည်ဆောက်ပြီးသည့်အခါ မတော်တဆ တတ်လာနိုင်သည့် error များကို သိရှိရန် events များကို စောင့်ကြည့်နိုင်ပါသည်။ kubectl get machines ဖြင့် control-plane ၏ အခြေနေကိုလည်း သိရှိနိုင်ပါသည်။

control-plane တည်ဆောက်ပြီးစီးသွားသည့်အခါတွင် AWS အပေါ်၌ တည်ဆောက်ခဲ့သည့် k8s cluster ၏ control-plane အား access ပြုလုပ်နိုင်သည့် kubeconfig file ကို local k8s cluster ၏ default namespace မှ secrets ထဲတွင် တွေ့မြင်မှာဖြစ်ပါသည်။ အောက်ဖေါ်ပြပါ command များဖြင့် kubconfig file ကို ဆွဲထုတ်ပြီး aws အပေါ်တွင် တည်ဆောက်ခဲ့သည့် cluster ကို access လုပ်နိုင်မှာ ဖြစ်ပါသည်။

git clone ထားသည့် workshop part-2 file ထဲမှ calico manifest ကို အသုံးပြုပြီး network plugin ကို AWS အပေါ်တွင်ရှိသော kubernetes cluster ၏ control-plane တွင် ထည့်သွင်းရမှာဖြစ်ပါသည်။ ထည့်သွင်းပြီးသည့်အခါ nodes status တွင် Ready ဖြစ်သွားပါမည်။

control-plane တည်ဆောက်ပြီးနောက် worker node တည်ဆောက်ရန် MachineDeployment resource နှင့် AWSMachineTemplate ကို အသုံးပြုပြီး တည်ဆောက်သွားရမှာ ဖြစ်ပါသည််။ ရှေ့တွင် ပြုလုပ်ခဲ့သည့်အတိုင်း sshKeyName ကို ထားပေးရမှာ ဖြစ်ပါသည်။

k8s MachineDelployment Like k8s Deployment Resource

worker ကို တည်ဆောက်ပြီးသည့်အခါ အောက်ပါ command များဖြင့် သိနိုင်၊ ကြည့်နိုင်ပါသည်။ kubectl get cluster တွင်လဲ k8s cluster တစ်ခုလုံးကို provisioned ပြီးစီးသည့် အခြေအနေကို မြင်ရမှာဖြစ်ပါသည်။

ယခုအခါတွင် local kubernetes cluster မှ AWS အပေါ်တွင် Kubernetes cluster ကို တည်ဆောက်ပြီးစီးပြီဖြစ်သည်။ နောက်ထပ်လဲ လိုချင်သလောက် cluster များကို ဒီပုံစံ အတိုင်း တည်ဆောက်သွားနိုင်မှာဖြစ်သည်။

Another Next k8s clusters

ယခု အခြေအနေတွင် စုစုပေါင်း cluster ၂လုံး တည်ဆောက်ပြီးဖြစ်ပါသည်။

AWS EC2 dashboard တွင်လဲ local kubernetes cluster မှ တည်ဆောက်ထားသော တခြား cluster များ၏ instance များကို တွေ့ရမှာဖြစ်ပါသည်။

AWS EC2 Dashboard

Last updated

Was this helpful?