openshift 4.3 calico + multus

Posted wandering-star

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openshift 4.3 calico + multus相关的知识,希望对你有一定的参考价值。

video

# 创建multus macvlan需要的ip地址
cat << EOF > calico.macvlan.yaml
apiVersion: operator.openshift.io/v1
kind: Network
metadata:
  name: cluster
spec:
  additionalNetworks: 
  - name: multus-macvlan-0
    namespace: demo
    type: SimpleMacvlan
    simpleMacvlanConfig:
      ipamConfig:
        type: static
        staticIPAMConfig:
          addresses:
          - address: 10.123.110.11/24
          routes:
  - name: multus-macvlan-1
    namespace: demo
    type: SimpleMacvlan
    simpleMacvlanConfig:
      ipamConfig:
        type: static
        staticIPAMConfig:
          addresses:
          - address: 10.123.110.22/24

EOF
oc apply -f calico.macvlan.yaml

# 检查创建的ip地址
oc get Network.operator.openshift.io -o yaml

# 创建pod,并配置multus,使用macvlan
cat << EOF > calico.pod.yaml
---
kind: Pod
apiVersion: v1
metadata:
  name: demo-pod1
  namespace: demo
  annotations:
    k8s.v1.cni.cncf.io/networks: ‘
      [{
        "name": "multus-macvlan-0"
      }]‘
spec:
  nodeSelector:
    kubernetes.io/hostname: ‘worker-0.ocp4.redhat.ren‘
  restartPolicy: Always
  containers:
    - name: demo
      image: >- 
        registry.redhat.ren:5443/docker.io/wangzheng422/centos:centos7-test
      env:
        - name: key
          value: value
      command: ["iperf3", "-s", "-p" ]
      args: [ "6666" ]
      imagePullPolicy: Always
---
kind: Pod
apiVersion: v1
metadata:
  name: demo-pod2
  namespace: demo
  annotations:
    k8s.v1.cni.cncf.io/networks: ‘
      [{
        "name": "multus-macvlan-1"
      }]‘
spec:
  nodeSelector:
    kubernetes.io/hostname: ‘worker-1.ocp4.redhat.ren‘
  restartPolicy: Always
  containers:
    - name: demo
      image: >- 
        registry.redhat.ren:5443/docker.io/wangzheng422/centos:centos7-test
      env:
        - name: key
          value: value
      command: ["iperf3", "-s", "-p" ]
      args: [ "6666" ]
      imagePullPolicy: Always

EOF
oc apply -f calico.pod.yaml

# 查看demo-pod2上的ip地址
var_ips=$(oc get pod -o json | jq -r ‘.items[] | select(.metadata.name != "demo-pod1") | .metadata.annotations["k8s.v1.cni.cncf.io/networks-status"] | fromjson | .[].ips[0] ‘ )
echo -e "$var_ips"

# oc get pod -o json | jq -r ‘ .items[] | select(.metadata.name != "demo-pod1") | { podname: .metadata.name, ip: ( .metadata.annotations["k8s.v1.cni.cncf.io/networks-status"] | fromjson | .[].ips[0] ) } | [.podname, .ip] | @tsv‘

# 从demo pod1上ping demo pod2上的2个ip地址
for var_i in $var_ips; do
  oc exec -n demo demo-pod1 -it -- ping -c 5 ${var_i}
done

# restore
oc delete -f calico.pod.yaml

cat << EOF > calico.macvlan.yaml
apiVersion: operator.openshift.io/v1
kind: Network
metadata:
  name: cluster
EOF
oc apply -f calico.macvlan.yaml

以上是关于openshift 4.3 calico + multus的主要内容,如果未能解决你的问题,请参考以下文章

Openshift开启Calico BGP 与 OVS性能PK

OpenShift 4.3环境中创建基于Go的Operator

openshift 4.3中安装helm3并通过helm方式部署应用

114.kubernetes之calico

k8s之calico网络

Calico 网络原理