当前位置:网站首页>The running kubernetes cluster wants to adjust the network segment address of pod

The running kubernetes cluster wants to adjust the network segment address of pod

2022-07-07 11:29:00 Jiangxl~

Running K8S Cluster adjustment Pod The segment address of

1. modify Pod Background of network segment address

Use sealos The deployment of K8S colony , default Pod Network segment is 100.64.0.0/16, There is no problem running in a privatized environment , But when the cluster is deployed in Alibaba cloud ECS In the following , adopt SLB Seven layers of load K8S Applications in the cluster , There will be access exceptions , The packet cannot be returned to SLB, After discussion with Alibaba cloud engineers, I learned ,SLB forwarding Proxy Network segment is 100.64.0.0/16, And K8S Pod The network segment address of conflicts , Thus, abnormal network phenomena may occur .
 Insert picture description here

2. At present K8S Cluster information

[[email protected] ~]# kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
k8s-master   Ready    master   6m43s   v1.19.16
k8s-node-1   Ready    <none>   6m13s   v1.19.16
k8s-node-2   Ready    <none>   6m13s   v1.19.16

Current Pod The network segment address is 100 Network segment , We need to adjust it to 10.10.0.0/18.

 Insert picture description here

3. First in K8S Build a cluster Pod

First in K8S Build a cluster Pod, Observe before and after modifying the network segment Pod Is it available .

1) Resource orchestration file

[[email protected]-master k8s]# cat nginx.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        - containerPort: 443
          name: https
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx-80-443
  namespace: default
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    port: 443
    protocol: TCP
    targetPort: 443
  selector:
    app: nginx
  type: NodePort

2) Deploy

[[email protected] k8s]# kubectl get all
NAME                         READY   STATUS    RESTARTS   AGE
pod/nginx-6b89b7f467-ct6md   1/1     Running   0          8m32s

NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP                      26m
service/nginx-80-443   NodePort    10.99.243.115   <none>        80:31575/TCP,443:31418/TCP   8m32s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   1/1     1            1           8m32s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-6b89b7f467   1         1         1       8m32s

4. adjustment K8S Clustered Pod Network segment

4.1. adjustment K8S Network segment of address pool

1. see K8S Default address pool 
[[email protected] k8s]# kubectl get ippool
NAME                  AGE
default-ipv4-ippool   18m

2. Adjust the address range of the address pool 
[[email protected] k8s]# kubectl edit ippool default-ipv4-ippool
  cidr: 10.10.0.0/18

 Insert picture description here

4.2. adjustment Controller-Manager Network segment of component

[[email protected] k8s]# vim /etc/kubernetes/manifests/kube-controller-manager.yaml 
    - --cluster-cidr=10.10.0.0/18

 Insert picture description here

4.4. adjustment Kube-proxy Segment address

[root@k8s-master k8s]# kubectl edit cm kube-proxy -n kube-system
    clusterCIDR: 10.10.0.0/18

4.5. adjustment K8S Cluster all nodes yaml The network segment address in the file

How many Node Just perform the same operation for how many times .

[[email protected] k8s]# kubectl get nodes k8s-master  -o yaml > master.yaml
[[email protected] k8s]# kubectl get nodes k8s-node-1  -o yaml > node-1.yaml
[[email protected] k8s]# kubectl get nodes k8s-node-2  -o yaml > node-2.yaml

[[email protected] k8s]# vim master.yaml
          v:"10.10.0.0/18": {}
spec:
  podCIDR: 10.10.0.0/18
  podCIDRs:
  - 10.10.0.0/18

 Insert picture description here

[root@k8s-master k8s]# kubectl delete node k8s-master
node "k8s-master" deleted
[root@k8s-master k8s]# kubectl apply -f master.yaml 
node/k8s-master created

[root@k8s-master k8s]# kubectl delete node k8s-node-1
node "k8s-node-1" deleted
[root@k8s-master k8s]# kubectl delete node k8s-node-2
node "k8s-node-2" deleted
[root@k8s-master k8s]# kubectl apply -f node-1.yaml 
node/k8s-node-1 created
[root@k8s-master k8s]# kubectl apply -f node-2.yaml 
node/k8s-node-2 created

4.6. All nodes restart kubelet

systemctl restart kubelet

4.7. restart K8S In the cluster Pod

[[email protected] k8s]# kubectl delete pod nginx-6b89b7f467-ct6md
pod "nginx-6b89b7f467-ct6md" deleted

[[email protected] k8s]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESS GATES
nginx-6b89b7f467-869m2   1/1     Running   0          23s   10.10.5.129   k8s-node-1   <none>           <none>

Pod The address has been successfully modified .

原网站

版权声明
本文为[Jiangxl~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070936112052.html