แนะนำ Kubernetes Kops สำหรับผู้เริ่มต้น
เผยแพร่แล้ว: 2021-06-13มาเรียนรู้เกี่ยวกับ Kops ซึ่งเป็นเครื่องมือปฏิบัติการของ Kubernetes กันเถอะ
Kubernetes เป็นหนึ่งในเครื่องมือ DevOps ที่ได้รับความนิยมมากที่สุด เนื่องจากมีระบบและฟีเจอร์การประสานคอนเทนเนอร์ที่น่าทึ่ง แม้ว่า Kubernetes จะมีฟังก์ชันมากมาย แต่การตั้งค่าคลัสเตอร์ Kubernetes ตั้งแต่เริ่มต้นก็เป็นเรื่องที่เจ็บปวด นี่คือจุดที่ Kops เข้ามาในภาพ
ด้วย Kops เป็นเรื่องง่ายที่จะสร้างคลัสเตอร์ Kubernetes บนผู้ให้บริการคลาวด์ เช่น AWS, Google Cloud เป็นต้น ทำให้การตั้งค่าคลัสเตอร์ Kubernetes นั้นไม่ยุ่งยาก และในบทความนี้ ฉันจะพูดถึงเครื่องมือที่ยอดเยี่ยมนี้
ค็อปคืออะไร?
Kops หรือที่เรียกว่าการดำเนินการของ Kubernetes เป็นโครงการโอเพ่นซอร์สอย่างเป็นทางการของ Kubernetes ซึ่งช่วยให้คุณสามารถสร้าง บำรุงรักษา อัปเกรด และทำลายคลัสเตอร์ Kubernetes ระดับโปรดักชั่นที่มีความพร้อมใช้งานสูง มันจัดเตรียมโครงสร้างพื้นฐานระบบคลาวด์โดยขึ้นอยู่กับความต้องการ นักพัฒนา Kops อธิบายว่าเป็น kubectl สำหรับคลัสเตอร์ Kubernetes
Kops ส่วนใหญ่จะใช้ในการปรับใช้คลัสเตอร์ AWS และ GCE Kubernetes Kops รองรับเฉพาะ AWS อย่างเป็นทางการ ผู้ให้บริการระบบคลาวด์อื่นๆ เช่น DigitalOcean, GCE และ OpenStack อยู่ในช่วงเบต้า
หากคุณเคยทำงานกับ kubectl มาก่อน คุณจะรู้สึกสบายใจที่จะทำงานกับ Kops Kops จัดเตรียมคำสั่งเพื่อสร้าง รับ อัปเดต ลบคลัสเตอร์ นอกจากนี้ Kops ยังรู้วิธีนำการเปลี่ยนแปลงไปใช้ในคลัสเตอร์ที่มีอยู่เนื่องจากใช้การกำหนดค่าแบบเปิดเผย ด้วย Kops คุณยังสามารถขยายขนาดคลัสเตอร์ Kubernetes ได้
ด้านล่างนี้เป็นคุณสมบัติของ Kops:
- ปรับใช้ต้นแบบ Kubernetes ที่มีความพร้อมใช้งานสูง
- รองรับการอัปเดตคลัสเตอร์โรลลิ่งส
- ทำการจัดเตรียมคลัสเตอร์ AWS และ GCE Kubernetes โดยอัตโนมัติ
- จัดการส่วนเสริมของคลัสเตอร์
- การเติมคำสั่งอัตโนมัติในบรรทัดคำสั่ง
- สร้างการกำหนดค่า CloudFormation และ Terraform
- รองรับรูปแบบการซิงโครไนซ์สถานะสำหรับการวิ่งแบบแห้งและแบบอัตโนมัติ idempotency
- สร้างกลุ่มอินสแตนซ์เพื่อรองรับคลัสเตอร์ที่แตกต่างกัน
การติดตั้ง Kops
ด้านล่างนี้เป็นขั้นตอนง่ายๆ ในการติดตั้ง Kops บนสภาพแวดล้อม Linux ฉันใช้ Ubuntu 20.x
ขั้นแรก ดาวน์โหลด Kops จากแพ็คเกจเผยแพร่ คำสั่งด้านล่างดาวน์โหลดแพ็คเกจล่าสุดของ Kops
geekflare@ip-170-11-26-119:~$ curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64 Saving to: 'kops-linux-amd64' 100%[=========================================================================================================================================================================>] 81,964,000 8.37MB/s in 7.1s 2021-06-10 16:23:19 (7.84 MB/s) - 'kops-linux-amd64' saved [81964000/81964000]
คุณต้องให้สิทธิ์ปฏิบัติการกับไฟล์ kops ที่คุณดาวน์โหลดและย้ายไปยังไดเร็กทอรี /usr/local/bin/
geekflare@ip-170-11-26-119:~$ sudo chmod +x kops-linux-amd64 geekflare@ip-170-11-26-119:~$ sudo mv kops-linux-amd64 /usr/local/bin/kops
การติดตั้งเสร็จสิ้น ตอนนี้คุณสามารถรันคำสั่ง kops เพื่อตรวจสอบการติดตั้ง
geekflare@ip-170-11-26-119:~$ kops kops is Kubernetes ops. kops is the easiest way to get a production grade Kubernetes cluster up and running. We like to think of it as kubectl for clusters. kops helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line. AWS (Amazon Web Services) is currently officially supported, with GCE and VMware vSphere in alpha support. Usage: kops [command] Available Commands: completion Output shell completion code for the given shell (bash or zsh). create Create a resource by command line, filename or stdin. delete Delete clusters,instancegroups, or secrets. describe Describe a resource. edit Edit clusters and other resources. export Export configuration. get Get one or many resources. import Import a cluster. replace Replace cluster resources. rolling-update Rolling update a cluster. toolbox Misc infrequently used commands. update Update a cluster. upgrade Upgrade a kubernetes cluster. validate Validate a kops cluster. version Print the kops version information. Flags: --alsologtostderr log to standard error as well as files --config string config file (default is $HOME/.kops.yaml) -h, --help help for kops --log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0) --log_dir string If non-empty, write log files in this directory --logtostderr log to standard error instead of files (default false) --name string Name of cluster --state string Location of state storage --stderrthreshold severity logs at or above this threshold go to stderr (default 2) -v, --v Level log level for V logs --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging Use "kops [command] --help" for more information about a command.
ตรวจสอบเวอร์ชั่น Kops เพื่อให้แน่ใจว่าติดตั้ง Kops อย่างถูกต้อง
geekflare@ip-170-11-26-119:~$ kops version Version 1.20.1 (git-5a27dad)
ให้เราดูคำสั่ง Kops ที่สำคัญบางคำสั่งซึ่งผู้ดูแลระบบใช้กันอย่างแพร่หลายในการดำเนินการ Kubernetes
คำสั่ง Kops
ด้านล่างนี้คือคำสั่ง Kops ที่ใช้กันอย่างแพร่หลายที่คุณต้องรู้
kops สร้าง
คำสั่ง kops create ใช้เพื่อลงทะเบียนคลัสเตอร์
ไวยากรณ์: kops สร้างคลัสเตอร์ <clustername>
มีพารามิเตอร์อื่นๆ มากมาย เช่น โซน ภูมิภาค ประเภทอินสแตนซ์ จำนวนโหนด ฯลฯ ซึ่งคุณสามารถเพิ่มได้นอกเหนือจากคำสั่งเริ่มต้น
kops อัพเดท
คำสั่ง kops update ใช้เพื่ออัพเดตคลัสเตอร์ด้วยข้อมูลจำเพาะของคลัสเตอร์ที่ระบุ
ไวยากรณ์: kops update cluster –name <clustername>
คุณสามารถเรียกใช้คำสั่งนี้ในโหมดแสดงตัวอย่างเพื่อให้อยู่ในด้านความปลอดภัย และเมื่อผลลัพธ์การแสดงตัวอย่างตรงกับความคาดหวังของคุณ คุณสามารถเรียกใช้คำสั่งด้วยแฟล็ก –yes เพื่อใช้การเปลี่ยนแปลงกับคลัสเตอร์
kops รับ
คำสั่ง kops get ใช้เพื่อแสดงรายการคลัสเตอร์ทั้งหมด
ไวยากรณ์: kops รับคลัสเตอร์
kops ลบ
คำสั่ง kops delete ใช้เพื่อลบคลัสเตอร์เฉพาะออกจากรีจิสตรีและทรัพยากรคลาวด์ทั้งหมดที่กำหนดให้กับคลัสเตอร์นั้น
ไวยากรณ์: kops ลบคลัสเตอร์ –name <clustername>
เช่นเดียวกับการอัปเดต คุณสามารถเรียกใช้คำสั่งนี้ในโหมดแสดงตัวอย่างได้เช่นกัน
kops กลิ้งอัพเดท
คำสั่ง kops rolling-update ใช้เพื่ออัปเดตคลัสเตอร์ Kubernetes เพื่อให้ตรงกับข้อกำหนดของระบบคลาวด์และ kops
ไวยากรณ์: kops ปรับปรุงคลัสเตอร์ –name <clustername>
เช่นเดียวกับการอัปเดต คุณสามารถเรียกใช้คำสั่งนี้ในโหมดแสดงตัวอย่างได้เช่นกัน
kops ตรวจสอบ
คำสั่ง kops validate จะตรวจสอบว่าคลัสเตอร์ที่คุณสร้างขึ้นนั้นทำงานหรือไม่ ตัวอย่างเช่น หากพ็อดและโหนดอยู่ในสถานะรอดำเนินการ คำสั่งตรวจสอบจะส่งคืนว่าคลัสเตอร์ยังไม่สมบูรณ์
ไวยากรณ์: kops ตรวจสอบคลัสเตอร์ –wait <specified_time>
คำสั่งนี้จะรอและตรวจสอบคลัสเตอร์ตามเวลาที่กำหนด ดังนั้น หากคุณต้องการตรวจสอบคลัสเตอร์เป็นเวลาห้านาที ให้รันคำสั่งด้วยเวลา 5m ตามเวลาที่กำหนด
นั่นคือทั้งหมดที่เกี่ยวกับพื้นฐานของ Kops ให้ฉันแสดงวิธีสร้างคลัสเตอร์ Kubernetes บน AWS โดยใช้ Kops
ตั้งค่า Kubernetes บน AWS โดยใช้ Kops
ก่อนที่คุณจะเริ่มต้นด้วยขั้นตอนที่กล่าวถึงด้านล่าง สิ่งเหล่านี้เป็นข้อกำหนดเบื้องต้นบางประการ:
- Ubuntu 20.04
- AWS CLI
- AWS Configure
กำลังติดตั้ง kubectl
ประการแรก ฉันจะติดตั้ง kubectl
Kubectl ใช้เพื่อเรียกใช้คำสั่งบรรทัดคำสั่งบนคลัสเตอร์ Kubernetes ดาวน์โหลดแพ็คเกจ kubectl
geekflare@ip-170-11-26-119:~$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 39.6M 100 39.6M 0 0 6988k 0 0:00:07 0:00:07 --:--:-- 6988k
คุณต้องให้สิทธิ์ปฏิบัติการกับไฟล์ที่ดาวน์โหลดและย้ายไปยังไดเร็กทอรี /usr/local/bin/
geekflare@ip-170-11-26-119:~$ chmod +x ./kubectl geekflare@ip-170-11-26-119:~$ sudo mv ./kubectl /usr/local/bin/kubectl
สร้างถัง S3
เมื่อคุณติดตั้งและกำหนดค่า AWS CLI ในเครื่อง Linux แล้ว คุณจะสามารถเรียกใช้คำสั่ง aws
ได้ ฉันติดตั้ง aws cli บนระบบ Ubuntu ของฉันแล้ว ดังนั้นให้ฉันเรียกใช้คำสั่งง่ายๆ ซึ่งจะแสดงรายการที่ฝากข้อมูลทั้งหมดใน S3
geekflare@ip-170-11-26-119:~$ aws s3 ls
มันจะว่างเปล่าเพราะฉันไม่มีที่ฝากข้อมูล s3 ใด ๆ ณ ตอนนี้ ให้ฉันตรวจสอบว่าอินสแตนซ์ ec2 ใดทำงานอยู่หรือไม่
geekflare@ip-170-11-26-119:~$ aws ec2 describe-instances { "Reservations": [] }
ซึ่งหมายความว่าไม่มีอินสแตนซ์ ec2 ทำงานอยู่ในขณะนี้
ตอนนี้ คุณต้องสร้างบัคเก็ต s3 โดยที่ Kops จะบันทึกข้อมูลสถานะของคลัสเตอร์ทั้งหมด ที่นี่ฉันกำลังสร้างที่ฝากข้อมูล s3 ในภูมิภาค us-west-2 ด้วยชื่อ geekkops-bucket-1132 คุณสามารถใช้ LocationConstraint เพื่อหลีกเลี่ยงข้อผิดพลาดใดๆ กับภูมิภาค
geekflare@ip-170-11-26-119:~$ aws s3api create-bucket --bucket geekkops-bucket-1132 --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2 { "Location": "http://geekkops-bucket-1132.s3.amazonaws.com/" }
ถ้าฉันแสดงรายการที่ aws s3 bucket
อีกครั้ง ฉันจะได้รับที่ฝากข้อมูลที่ฉันเพิ่งสร้างขึ้น
geekflare@ip-170-11-26-119:~$ aws s3 ls 2021-06-10 16:30:13 geekkops-bucket-1132
เรียกใช้คำสั่งด้านล่างเพื่อเปิดใช้งานเวอร์ชันสำหรับบัคเก็ต s3
geekflare@ip-170-11-26-119:~$ aws s3api put-bucket-versioning --bucket geekkops-bucket-1132 --versioning-configuration Status=Enabled
สร้างคีย์
สร้างคีย์ ssh ที่ Kops จะใช้สำหรับการเข้าสู่ระบบคลัสเตอร์และการสร้างรหัสผ่าน
geekflare@ip-170-11-26-119:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ubuntu/.ssh/id_rsa. Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub. The key fingerprint is: SHA256:fH4JCBXMNRqzk1hmoK+cXmwSFaeBsuGBA5IWMkNuvq0 geekflare@ip-170-11-26-119 The key's randomart image is: +---[RSA 2048]----+ |O=. .++Xoo | |B++ .. @o* . | |.= =. = = | |ooooo | | . . . S o | | o. = o . . | | . .= + . o | | .. + . | | E . | +----[SHA256]-----+
ตัวแปรสภาพแวดล้อมการส่งออก
เปิดเผยชื่อคลัสเตอร์และบัคเก็ต s3 เป็นตัวแปรสภาพแวดล้อม ซึ่งจะมีผลกับเซสชันปัจจุบันเท่านั้น ฉันกำลังใช้ส่วนต่อท้าย '.k8s.local' เพราะฉันไม่ได้ใช้ DNS ที่กำหนดค่าไว้ล่วงหน้า
geekflare@ip-170-11-26-119:~$ export KOPS_CLUSTER_NAME=geekdemo1.k8s.local geekflare@ip-170-11-26-119:~$ export KOPS_STATE_STORE=s3://geekkops-bucket-1132
สร้างคลัสเตอร์
ใช้คำสั่ง kops create เพื่อสร้างคลัสเตอร์ ด้านล่างนี้คือพารามิเตอร์ที่ฉันใช้เพื่อสร้างคลัสเตอร์ Kubernetes บน AWS โดยใช้ Kops:

-
--cloud
บอกผู้ให้บริการคลาวด์ที่ฉันใช้อยู่ -
--zones
คือโซนที่อินสแตนซ์คลัสเตอร์จะได้รับการปรับใช้ -
--node-count
คือจำนวนโหนดที่จะปรับใช้ในคลัสเตอร์ Kubernetes -
--node-size
และ --master---master-size
เป็นประเภทอินสแตนซ์ ec2 ฉันกำลังใช้อินสแตนซ์ขนาดเล็ก -
--name
คือชื่อคลัสเตอร์
geekflare@ip-170-11-26-119:~$ kops create cluster --cloud=aws --zones=eu-central-1a --node-count=1 --node-size=t2.micro --master-size=t2.micro --name=${KOPS_CLUSTER_NAME} I0216 16:35:24.225238 4326 subnets.go:180] Assigned CIDR 172.20.32.0/19 to subnet eu-central-1a I0216 16:35:24.068088 4326 create_cluster.go:717] Using SSH public key: /home/ubuntu/.ssh/id_rsa.pub Previewing changes that will be made: I0216 16:35:24.332590 4326 apply_cluster.go:465] Gossip DNS: skipping DNS validation I0216 16:35:24.392712 4326 executor.go:111] Tasks: 0 done / 83 total; 42 can run W0216 16:35:24.792113 4326 vfs_castore.go:604] CA private key was not found I0216 16:35:24.938057 4326 executor.go:111] Tasks: 42 done / 83 total; 17 can run I0216 16:35:25.436407 4326 executor.go:111] Tasks: 59 done / 83 total; 18 can run I0216 16:35:25.822395 4326 executor.go:111] Tasks: 77 done / 83 total; 2 can run I0216 16:35:25.823088 4326 executor.go:111] Tasks: 79 done / 83 total; 2 can run I0216 16:35:26.406919 4326 executor.go:111] Tasks: 81 done / 83 total; 2 can run I0216 16:35:27.842148 4326 executor.go:111] Tasks: 83 done / 83 total; 0 can run LaunchTemplate/master-eu-central-1a.masters.geekdemo1.k8s.local AssociatePublicIP true HTTPPutResponseHopLimit 1 HTTPTokens optional IAMInstanceProfile name:masters.geekdemo1.k8s.local id:masters.geekdemo1.k8s.local ImageID 099720109477/ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20210119.1 InstanceType t2.micro RootVolumeSize 64 RootVolumeType gp2 RootVolumeEncryption false RootVolumeKmsKey SSHKey name:kubernetes.geekdemo1.k8s.local-3e:19:92:ca:dd:64:d5:cf:ff:ed:3a:92:0f:40:d4:e8 id:kubernetes.geekdemo1.k8s.local-3e:19:92:ca:dd:64:d5:cf:ff:ed:3a:92:0f:40:d4:e8 SecurityGroups [name:masters.geekdemo1.k8s.local] SpotPrice Tags {k8s.io/cluster-autoscaler/node-template/label/kubernetes.io/role: master, k8s.io/cluster-autoscaler/node-template/label/kops.k8s.io/instancegroup: master-eu-central-1a, k8s.io/role/master: 1, kops.k8s.io/instancegroup: master-eu-central-1a, Name: master-eu-central-1a.masters.geekdemo1.k8s.local, KubernetesCluster: geekdemo1.k8s.local, kubernetes.io/cluster/geekdemo1.k8s.local: owned, k8s.io/cluster-autoscaler/node-template/label/node-role.kubernetes.io/master: } Subnet/eu-central-1a.geekdemo1.k8s.local ShortName eu-central-1a VPC name:geekdemo1.k8s.local AvailabilityZone eu-central-1a CIDR 172.20.32.0/19 Shared false Tags {KubernetesCluster: geekdemo1.k8s.local, kubernetes.io/cluster/geekdemo1.k8s.local: owned, SubnetType: Public, kubernetes.io/role/elb: 1, Name: eu-central-1a.geekdemo1.k8s.local} VPC/geekdemo1.k8s.local CIDR 172.20.0.0/16 EnableDNSHostnames true EnableDNSSupport true Shared false Tags {kubernetes.io/cluster/geekdemo1.k8s.local: owned, Name: geekdemo1.k8s.local, KubernetesCluster: geekdemo1.k8s.local} VPCDHCPOptionsAssociation/geekdemo1.k8s.local VPC name:geekdemo1.k8s.local DHCPOptions name:geekdemo1.k8s.local Must specify --yes to apply changes Cluster configuration has been created. Suggestions: * list clusters with: kops get cluster * edit this cluster with: kops edit cluster geekdemo1.k8s.local * edit your node instance group: kops edit ig --name=geekdemo1.k8s.local nodes-eu-central-1a * edit your master instance group: kops edit ig --name=geekdemo1.k8s.local master-eu-central-1a Finally configure your cluster with: kops update cluster --name geekdemo1.k8s.local --yes –admin
รันคำสั่ง kops get เพื่อดูว่ามีการสร้างคลัสเตอร์หรือไม่
geekflare@ip-170-11-26-119:~$ kops get cluster NAME CLOUD ZONES geekdemo1.k8s.local aws eu-central-1a
อัปเดตคลัสเตอร์
เมื่อต้องการใช้ข้อมูลจำเพาะของคลัสเตอร์ที่ระบุกับคลัสเตอร์ ให้รันคำสั่ง kops update
geekflare@ip-170-11-26-119:~$ kops update cluster --name geekdemo1.k8s.local --yes --admin I0216 16:38:16.800767 4344 apply_cluster.go:465] Gossip DNS: skipping DNS validation I0216 16:38:16.919282 4344 executor.go:111] Tasks: 0 done / 83 total; 42 can run W0216 16:38:17.343336 4344 vfs_castore.go:604] CA private key was not found I0216 16:38:18.421652 4344 keypair.go:195] Issuing new certificate: "etcd-clients-ca" I0216 16:38:18.450699 4344 keypair.go:195] Issuing new certificate: "etcd-peers-ca-main" I0216 16:38:19.470785 4344 keypair.go:195] Issuing new certificate: "etcd-manager-ca-main" I0216 16:38:19.531852 4344 keypair.go:195] Issuing new certificate: "etcd-peers-ca-events" I0216 16:38:19.551601 4344 keypair.go:195] Issuing new certificate: "apiserver-aggregator-ca" I0216 16:38:19.571834 4344 keypair.go:195] Issuing new certificate: "etcd-manager-ca-events" I0216 16:38:19.592090 4344 keypair.go:195] Issuing new certificate: "master" W0216 16:38:19.652894 4344 vfs_castore.go:604] CA private key was not found I0216 16:38:19.653013 4344 keypair.go:195] Issuing new certificate: "ca" I0216 16:38:24.344075 4344 executor.go:111] Tasks: 42 done / 83 total; 17 can run I0216 16:38:24.306125 4344 executor.go:111] Tasks: 59 done / 83 total; 18 can run I0216 16:38:26.189798 4344 executor.go:111] Tasks: 77 done / 83 total; 2 can run I0216 16:38:26.190464 4344 executor.go:111] Tasks: 79 done / 83 total; 2 can run I0216 16:38:26.738600 4344 executor.go:111] Tasks: 81 done / 83 total; 2 can run I0216 16:38:28.810100 4344 executor.go:111] Tasks: 83 done / 83 total; 0 can run I0216 16:38:29.904257 4344 update_cluster.go:313] Exporting kubecfg for cluster kops has set your kubectl context to geekdemo1.k8s.local Cluster is starting. It should be ready in a few minutes. Suggestions: * validate cluster: kops validate cluster --wait 10m * list nodes: kubectl get nodes --show-labels * ssh to the master: ssh -i ~/.ssh/id_rsa [email protected] * the ubuntu user is specific to Ubuntu. If not using Ubuntu please use the appropriate user based on your OS. * read about installing addons at: https://kops.sigs.k8s.io/operations/addons.
หากคุณตรวจสอบทันทีว่าโหนด Kubernetes กำลังทำงานอยู่หรือไม่ คุณจะได้รับข้อผิดพลาด คุณต้องอดทนเล็กน้อยและรอสักครู่ (5-10) จนกว่าคลัสเตอร์จะถูกสร้างขึ้น
geekflare@ip-170-11-26-119:~$ kubectl get nodes Unable to connect to the server: dial tcp: lookup api-geekdemo1-k8s-local-dason2-1001342368.eu-central-1.elb.amazonaws.com on 127.0.0.53:53: no such host
ตรวจสอบคลัสเตอร์
ฉันกำลังเรียกใช้คำสั่งตรวจสอบความถูกต้องเป็นเวลา 5 นาทีเพื่อตรวจสอบว่าคลัสเตอร์ทำงานเป็นปกติหรือไม่ ในการตรวจสอบผลลัพธ์ คุณจะสามารถดูรายละเอียดโหนดเมื่อใช้งานได้
geekflare@ip-170-11-26-119:~$ kops validate cluster --wait 5m Validating cluster geekdemo1.k8s.local INSTANCE GROUPS NAME ROLE MACHINETYPE MIN MAX SUBNETS master-eu-central-1a Master t2.micro 1 1 eu-central-1a nodes-eu-central-1a Node t2.micro 1 1 eu-central-1a
แสดงรายการโหนดและพ็อด
ตอนนี้ให้รันคำสั่งด้านล่างเพื่อตรวจสอบว่าโหนดทั้งหมดพร้อมและทำงานอยู่หรือไม่ คุณสามารถเห็นทั้งสถานะมาสเตอร์และโหนดพร้อม
geekflare@ip-170-11-26-119:~$ kubectl get nodes NAME STATUS ROLES AGE VERSION ip-173-19-35-156.eu-central-1.compute.internal Ready master 10m v1.20.1 ip-172-36-23-149.eu-central-1.compute.internal Ready node 5m38s v1.20.1
คุณตรวจสอบพ็อดทั้งหมดที่ทำงานอยู่ในคลัสเตอร์ Kubernetes ได้
geekflare@ip-170-11-26-119:~$ kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system dns-controller-8d8889c4b-xp9dl 1/1 Running 0 8m26s kube-system etcd-manager-events-ip-173-19-35-156.eu-central-1.compute.internal 1/1 Running 0 10m kube-system etcd-manager-main-ip-173-19-35-156.eu-central-1.compute.internal 1/1 Running 0 10m kube-system kops-controller-9skdk 1/1 Running 3 6m51s kube-system kube-apiserver-ip-173-19-35-156.eu-central-1.compute.internal 2/2 Running 0 10m kube-system kube-controller-manager-ip-173-19-35-156.eu-central-1.compute.internal 1/1 Running 6 10m kube-system kube-dns-696cb84c7-g8nhb 3/3 Running 0 4m27s kube-system kube-dns-autoscaler-55f8f75459-zlxbr 1/1 Running 0 7m18s kube-system kube-proxy-ip-173-19-35-156.eu-central-1.compute.internal 1/1 Running 0 10m kube-system kube-proxy-ip-172-36-23-149.eu-central-1.compute.internal 1/1 Running 0 7m2s kube-system kube-scheduler-ip-173-19-35-156.eu-central-1.compute.internal 1/1 Running 5 10m
ลบคลัสเตอร์
เช่นเดียวกับการสร้างคลัสเตอร์ Kubernetes การลบคลัสเตอร์ Kubernetes โดยใช้ Kops นั้นตรงไปตรงมามาก คำสั่ง kops delete จะลบทรัพยากรคลาวด์ทั้งหมดของคลัสเตอร์และรีจิสตรีของคลัสเตอร์เอง
geekflare@ip-170-11-26-119:~$ kops delete cluster --name geekdemo1.k8s.local --yes TYPE NAME ID autoscaling-config master-eu-central-1a.masters.geekdemo1.k8s.local lt-0cc11aec1943204e4 autoscaling-config nodes-eu-central-1a.geekdemo1.k8s.local lt-0da65d2eaf6de9f5c autoscaling-group master-eu-central-1a.masters.geekdemo1.k8s.local master-eu-central-1a.masters.geekdemo1.k8s.local autoscaling-group nodes-eu-central-1a.geekdemo1.k8s.local nodes-eu-central-1a.geekdemo1.k8s.local dhcp-options geekdemo1.k8s.local dopt-0403a0cbbfbc0c72b iam-instance-profile masters.geekdemo1.k8s.local masters.geekdemo1.k8s.local iam-instance-profile nodes.geekdemo1.k8s.local nodes.geekdemo1.k8s.local iam-role masters.geekdemo1.k8s.local masters.geekdemo1.k8s.local iam-role nodes.geekdemo1.k8s.local nodes.geekdemo1.k8s.local instance master-eu-central-1a.masters.geekdemo1.k8s.local i-069c73f2c23eb502a instance nodes-eu-central-1a.geekdemo1.k8s.local i-0401d6b0d4fc11e77 iam-instance-profile:nodes.geekdemo1.k8s.local ok load-balancer:api-geekdemo1-k8s-local-dason2 ok iam-instance-profile:masters.geekdemo1.k8s.local ok iam-role:masters.geekdemo1.k8s.local ok instance:i-069c73f2c23eb502a ok autoscaling-group:nodes-eu-central-1a.geekdemo1.k8s.local ok iam-role:nodes.geekdemo1.k8s.local ok instance:i-0401d6b0d4fc11e77 ok autoscaling-config:lt-0cc11aec1943204e4 ok autoscaling-config:lt-0da65d2eaf6de9f5c ok autoscaling-group:master-eu-central-1a.masters.geekdemo1.k8s.local ok keypair:key-0d82g920j421b89dn ok Deleted kubectl config for geekdemo1.k8s.local Deleted cluster: "geekdemo1.k8s.local"
บทสรุป
ฉันหวังว่าบทความเกี่ยวกับ Kops นี้จะเป็นประโยชน์ และคุณต้องเรียนรู้สิ่งใหม่ในวันนี้ Kops เป็นเครื่องมือที่ยอดเยี่ยมในการทำงานกับ Kubernetes บนคลาวด์ ลองทำตามขั้นตอนที่กล่าวถึงในบทความนี้และตั้งค่าคลัสเตอร์ Kubernetes บน AWS โดยใช้ Kops