Hướng dẫn từng bước về cách cấu hình tự động mở rộng cluster Kubernetes HI GIO.
Cài đặt tanzu-cli
Tạo cluster-autoscaler deployment từ tanzu package sử dụng tanzu-cli
Kích hoạt tự động mở rộng cho cluster của bạn
kiểm tra tự động mở rộng cluster
Xóa cluster-autoscaler deployment và dọn dẹp tài nguyên thử nghiệm.
Bastion Ubuntu có thể kết nối với Kubernetes cluster của bạn.
Có quyền truy cập vào Kubernetes cluster của bạn.
Bước 1: Cài đặt tanzu-cli
Bước 2: Tạo deployment cluster-autoscaler từ gói tanzu bằng tanzu-cli
Chuyển sang context Kubernetes của bạn
Liệt kê các phiên bản cluster-autoscaler có sẵn trong gói tanzu và ghi lại tên phiên bản
Tạo secret kubeconfig có tên cluster-autoscaler-mgmt-config-secret trong namespace kube-system
Tạo file cluster-autoscaler-values.yaml
Cài đặt cluster-autoscaler
Cấu hình số lượng node tối thiểu và tối đa trong cluster
Lấy tên và namespace của machinedeployments
Cấu hình cluster-api-autoscaler-node-group-min-size and cluster-api-autoscaler-node-group-max-size
Bật cluster autoscale cho cluster của bạn
Bước 3: Kiểm tra tự động mở rộng cluster
Lấy số lượng node hiện tại
kubectl get nodes
Tạo file test-autoscale.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
topologySpreadConstraints: #Spreads pods across different nodes (ensures no node has more pods than others)
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: nginxÁp dụng file test-autoscale.yaml để triển khai 2 replicas nginx pod trong namespace default (lệnh này sẽ kích hoạt tạo một worker node mới)
Kiểm tra deployment nginx
Chờ một chút và bạn sẽ thấy một worker node mới đã được cấp phát và nginx pod mới có trạng thái Running.
Dọn dẹp tài nguyên thử nghiệm
Xóa deployment cluster-autoscaler (Tùy chọn)
#Install tanzu-cli to ubuntu
sudo apt update
sudo apt install -y ca-certificates curl gpg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://storage.googleapis.com/tanzu-cli-installer-packages/keys/TANZU-PACKAGING-GPG-RSA-KEY.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/tanzu-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/tanzu-archive-keyring.gpg] https://storage.googleapis.com/tanzu-cli-installer-packages/apt tanzu-cli-jessie main" | sudo tee /etc/apt/sources.list.d/tanzu.list
sudo apt update
sudo apt install -y tanzu-cli
#Verify tanzu-cli installation
tanzu versionkubectl config use-context <your context name>tanzu package available list cluster-autoscaler.tanzu.vmware.comkubectl create secret generic cluster-autoscaler-mgmt-config-secret \
--from-file=value=<path to your kubeconfig file> \
-n kube-systemarguments:
ignoreDaemonsetsUtilization: true
maxNodeProvisionTime: 15m
maxNodesTotal: 0 #Leave this value as 0. We will define the max and min number of nodes later.
metricsPort: 8085
scaleDownDelayAfterAdd: 10m
scaleDownDelayAfterDelete: 10s
scaleDownDelayAfterFailure: 3m
scaleDownUnneededTime: 10m
clusterConfig:
clusterName: "demo-autoscale-tkg" #adjust here
clusterNamespace: "demo-autoscale-tkg-ns" #adjust here
paused: falsetanzu package install cluster-autoscaler \
--package cluster-autoscaler.tanzu.vmware.com \
--version <version available> \ #adjust the version listed above to match your kubernetes version
--values-file 'cluster-autoscaler-values.yaml' \
--namespace tkg-system #please do not change, this is default namespace for tanzu packagekubectl get machinedeployments.cluster.x-k8s.io -Akubectl annotate machinedeployment <machinedeployment name> cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size=<number min> -n <machinedeployment namespace>
kubectl annotate machinedeployment <machinedeployment name> cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size=<number max> -n <machinedeployment namespace>kubectl apply -f test-autoscale.yamlkubectl get podskubectl describe pod nginx-589656b9b5-mcm5j | grep -A 10 EventsWarning FailedScheduling 2m53s default-scheduler 0/2 nodes are available: 1 node(s) didn't match pod topology spread constraints, 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }. preemption: 0/2 nodes are available: 1 No preemption victims found for incoming pod, 1 Preemption is not helpful for scheduling.
Normal TriggeredScaleUp 2m43s cluster-autoscaler pod triggered scale-up: [{MachineDeployment/demo-autoscale-tkg-ns/demo-autoscale-tkg-worker-node-pool-1 1->2 (max: 5)}]kubectl delete -f test-autoscale.yamltanzu package installed delete cluster-autoscaler -n tkg-system -y









