可以通过修改 Kubernetes API server 的参数来开启或关闭高可用选项。具体步骤如下:
- 编辑 kube-apiserver 配置文件,找到
--ha-enabled
参数
apiVersion: v1
kind: Pod
metadata:
name: kube-apiserver
spec:
containers:
- name: kube-apiserver
image: k8s.gcr.io/kube-apiserver:v1.21.0
command:
- kube-apiserver
- --advertise-address=192.168.10.100
- --bind-address=192.168.10.100
- --insecure-port=0
- --secure-port=6443
- --authorization-mode=Node,RBAC
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --enable-bootstrap-token-auth=true
- --token-auth-file=/etc/kubernetes/pki/token.csv
- --service-cluster-ip-range=10.96.0.0/12
- --service-node-port-range=30000-32767
- --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
- --etcd-certfile=/etc/kubernetes/pki/etcd/server.crt
- --etcd-keyfile=/etc/kubernetes/pki/etcd/server.key
- --etcd-servers=https://192.168.10.101:2379,https://192.168.10.102:2379,https://192.168.10.103:2379
- --enable-admission-plugins=NodeRestriction,PodSecurityPolicy,DefaultStorageClass,LimitRanger,MutatingAdmissionWebhook,ValidatingAdmissionWebhook
- --admission-control-config-file=/etc/kubernetes/admission/config.yaml
- --event-ttl=1h
- --runtime-config=api/all=true
- --logtostderr=true
- --v=2
- --ha-enabled=true # 修改此处
- 将
--ha-enabled
参数设置为true
或false
--ha-enabled=true
表示开启高可用选项--ha-enabled=false
表示关闭高可用选项
- 保存 kube-apiserver 配置文件并重新启动 kube-apiserver Pod,使修改生效
$ kubectl apply -f kube-apiserver.yaml