OpenShift 4.10环境中的Multus静态ip

mutus支持的网络模式

 

 整体的架构图如下

在ip分配上,既支持静态ip也支持动态ip的模式

 

 OpenShift 4的版本中已经开启Multus的多网络平面组件,因此只需要配置就可以使用

oc edit  networks.operator.openshift.io cluster

加入一段

spec:
  additionalNetworks:
  - name: static-net
    namespace: myproject
    rawCNIConfig: |-
      {
        "name": "static-net",
        "cniVersion": "0.3.1",
        "type": "ipvlan",
        "ipam": {
          "type": "static"
        }
      }
    type: Raw

静态ip可以在cluster的addionalNetwork里面指定也可以在Deployment里面指定,完成后确认生成了network attachment definition

[root@bastion ~]oc get network-attachment-definition
NAME         AGE
static-net   32m

修改Deployment

[root@bastion ~]# cat tomcat.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: tomcat
    app.kubernetes.io/component: tomcat
    app.kubernetes.io/instance: tomcat
  name: tomcat
  namespace: myproject
spec:
  replicas: 1
  selector:
    matchLabels:
      deployment: tomcat
  template:
    metadata:
      annotations:
        k8s.v1.cni.cncf.io/networks: |-
          [
           {
             "name": "static-net",
             "namespace": "myproject",
             "ips": ["192.168.12.77/24"] 
           }
          ]
        openshift.io/generated-by: OpenShiftNewApp
      labels:
        deployment: tomcat
    spec:
      containers:
      - command:
        - /sbin/init
        image: docker.io/centos/tools:latest
        imagePullPolicy: IfNotPresent
        name: samplepod
        ports:
        - containerPort: 8080
          protocol: TCP

 

"ips": ["192.168.12.77/24"] 意思是供应一个固定ip为192.168.12.77,掩码为255.255.255.0

创建完成后,进入Pod查看ip

 

 

sh-4.2$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8951
        inet 10.129.2.25  netmask 255.255.254.0  broadcast 10.129.3.255
        inet6 fe80::cc0:8bff:fe3b:1696  prefixlen 64  scopeid 0x20<link>
        ether 0a:58:0a:81:02:19  txqueuelen 0  (Ethernet)
        RX packets 8  bytes 816 (816.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1216 (1.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

net1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 192.168.12.77  netmask 255.255.255.0  broadcast 192.168.12.255
        inet6 fe80::685:7d00:116:e3b4  prefixlen 64  scopeid 0x20<link>
        ether 06:85:7d:16:e3:b4  txqueuelen 0  (Ethernet)
        RX packets 72  bytes 3082 (3.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 1146 (1.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

sh-4.2$ 

 

posted @ 2022-05-23 15:10  ericnie  阅读(352)  评论(0编辑  收藏  举报