1. 修改k8s相关配置kube-apiserver: --pod-network-cidr

kube-proxy: --cluster-cidr

kube-controller-manager: --cluster-cidr

2.修改calico IP pool

配置calico连接etcd:

calicoctl get ippool -o wide --config /etc/calico/calicoctl.cfgapiVersion:projectcalico.org/v3kind:CalicoAPIConfigmetadata:spec:etcdEndpoints:https://192.168.0.5:2379,https://192.168.0.6:2379,https://192.168.0.7:2379etcdKeyFile:/etc/calico/certs/key.pemetcdCertFile:/etc/calico/certs/cert.crtetcdCACertFile:/etc/calico/certs/ca_cert.crt

(1). 增加新的 ip pool(k8s组件中设置的--pod-network-cidr --cluster-cidr):

calicoctl create -f -<

apiVersion: projectcalico.org/v3

kind: IPPool

metadata:

name: new-pool

spec:

cidr: 172.0.0.0/15

ipipMode: Always

natOutgoing: true

EOF

(2). 禁用旧的 IP pool

在旧的ip pool的spec中增加一个字段:disabled: true

calicoctl get ippool -o yaml --config /etc/calico/calicoctl.cfg > pool.yaml

apiVersion: projectcalico.org/v3

items:

- apiVersion: projectcalico.org/v3

kind: IPPool

metadata:

creationTimestamp: 2018-12-07T13:17:31Z

name: default-pool

resourceVersion: "3807"

uid: 73fd5867-fa22-11e8-b0e7-5254c80ff311

spec:

blockSize: 26

cidr: 10.233.64.0/18

ipipMode: Always

natOutgoing: true

nodeSelector: all()

disabled: true # new add

- apiVersion: projectcalico.org/v3

kind: IPPool

metadata:

creationTimestamp: 2019-10-20T07:45:14Z

name: new-pool

resourceVersion: "704829464"

uid: 8d40e24e-f30d-11e9-a071-5254c80ff311

spec:

blockSize: 26

cidr: 172.0.0.0/15

ipipMode: Always

natOutgoing: true

nodeSelector: all()

vxlanMode: Never

kind: IPPoolList

metadata:

resourceVersion: "704836168"

3. 重置k8s集群节点 podCIDR

# 获取节点yaml文件

kubectl get node node1 -o yaml > node1.yaml

# 修改yaml文件中spec.podCIDR字段

# 按照规划的CIDR地址块进行修改

spec:

podCIDR: 172.0.0.0/24

# 修改yaml文件后,由于node对象不能直接覆盖创建,需要先删除节点,再重新创建

kubectl delete nodes node1

kubectl create -f node1.yaml

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐