200字
DCS中k8s集群pod-macvlan
2025-10-29
2025-10-29

概览

一、macvlan工作负载创建

1.1 安装cni-plugins-linux-arm64-v1.3.0.tgk

上传cni-plugins-linux-arm64-v1.3.0.tgk到/home/gandalf文件中

"相关文件及安装包"文件夹中

安装到所有节点中:所有master节点 、所有node节点

[root@k8s-master ~]sudo tar -xzf /home/gandalf/cni-plugins-linux-arm64-v1.3.0.tgz -C /opt/cni/bin
[root@k8s-master ~]sudo chmod 755 /opt/cni/bin

1.2 启动macvlan插件

master节点中

[root@k8s-master ~]vim multus-daemonset.yml

"相关文件及安装包"文件夹中

配置文件如下:

spec:
  selector:
    matchLabels:
      name: multus
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        tier: node
        app: multus
        name: multus
    spec:
      hostNetwork: true
      tolerations:
      - operator: Exists
        effect: NoSchedule
      - operator: Exists
        effect: NoExecute
      serviceAccountName: multus
      containers:
      - name: kube-multus
        image: swr.cn-north-4.myhuaweicloud.com/iridiumarm/multus-cni:snapshot   #182行
        command: ["/thin_entrypoint"]
        args:
        - "--multus-conf-file=auto"
        - "--multus-autoconfig-dir=/host/etc/cni/net.d"
        - "--cni-conf-dir=/host/etc/cni/net.d"
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
          limits:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: true
        terminationMessagePolicy: FallbackToLogsOnError
        volumeMounts:
        - name: cni
          mountPath: /host/etc/cni/net.d
        - name: cnibin
          mountPath: /host/opt/cni/bin
        - name: multus-cfg
          mountPath: /tmp/multus-conf
      initContainers:
        - name: install-multus-binary
          image: swr.cn-north-4.myhuaweicloud.com/iridiumarm/multus-cni:snapshot  #207行
          command: ["/install_multus"]
          args:
            - "--type"
            - "thin"
          resources:
            requests:
              cpu: "10m"
              memory: "15Mi"
          securityContext:
            privileged: true
          terminationMessagePolicy: FallbackToLogsOnError
          volumeMounts:
            - name: cnibin
              mountPath: /host/opt/cni/bin
              mountPropagation: Bidirectional

1.3 启动 multus-daemonset.yml

master节点启动

#启动
kubectl apply -f multus-daemonset.yml
​
#查看启动状态
kubectl get pods -n kube-system  -l app=multus

二、声明CRD,关联CNI网络配置

2.1 创建mac-vlan.yaml文件

master节点

"相关文件及安装包"文件夹中

apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan-net
  namespace: webcli
spec:
  config: |
    {
      "cniVersion": "0.3.1",
      "type": "macvlan",
      "master": "enp4s0",    #虚拟机绑定的网卡
      "mode": "bridge",
      "ipam": {
        "type": "static"
      }
    }

2.2 启动mac-vlan.yaml配置文件

[root@k8s-master ~]kubectl apply -f mac-vlan.yaml -n webcli

2.3 查看启动状态

[root@k8s-master ~]kubectl -n webcli get net-attach-def
NAME             AGE
macvlan-net   134m

三、创建无状态工作负载


配置:(注意格式)

metadata:
      annotations:
        k8s.v1.cni.cncf.io/networks: |
          [
            {
              "name": "macvlan-net",
              "ips": [ "192.168.6.248/24" ],
              "gateway": "192.168.6.254"
            }
          ]

DCS中k8s集群pod-macvlan
作者
roche
发表于
2025-10-29
License
CC BY-NC-SA 4.0