0

我正在尝试使用静态 IP 配置我的 pod。发现你可以用 multus 做到这一点。我的主要 cni 是印花布,一些示例配置如下:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: dnsmasqconf-pv1
  namespace: vt
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: ceph-rbd-sc
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dnsmasq1
  annotations:
    k8s.v1.cni.cncf.io/networks: vt/macvlan
#     "cni.projectcalico.org/ipAddrs": "[\"192.168.0.131\"]"
  namespace: vt
  labels:
    name: dnsmasq1
#  podIP: 192.168.0.131
spec:
#  serviceName: "dnsmasq1"
  replicas: 1
  selector:
    matchLabels:
      name: dnsmasq1
  template:
    metadata:
      labels:
        name: dnsmasq1
    spec:
      hostNetwork: false
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchLabels:
                name: dnsmasq1
            topologyKey: "kubernetes.io/hostname"
      hostname: dnsmasq1
      containers:
      - name: dnsmasq1
        image: jpillora/dnsmasq
        ports:
        - containerPort: 8080
        imagePullPolicy: IfNotPresent
        env:
        - name: HTTP_USER
          value: "user"
        - name: HTTP_PASS
          value: "password"
        volumeMounts:
        - mountPath: /mnt/config
          name: dnsmasqconf-pv1
      nodeSelector:
        etiket: worker
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 8.8.8.8
      volumes:
      - name: dnsmasqconf-pv1
        persistentVolumeClaim:
          claimName: dnsmasqconf-pv1

并且名为“vt/macvlan”的注释如下所示:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan
  namespace: vt
spec:
  config: '{
            "cniVersion": "0.3.1",
            "type": "macvlan",
            "master": "eth0",
            "mode": "bridge",
            "ipam": {
                "type": "host-local",
                "ranges": [
                    [ {
                         "subnet": "192.168.0.0/24",
                         "rangeStart": "192.168.0.131",
                         "rangeEnd": "192.168.0.131",
                         "gateway": "192.168.0.7"
                    } ]
                ]
            }
        }'

我也尝试过这样的事情:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: eth0
  namespace: vt
spec:
  config: '{
      "cniVersion": "0.3.1",
      "type": "macvlan",
      "master": "ens18",
      "mode": "bridge",
      "ipam": {
        "type": "multus",
        "subnet": "192.168.0.0/24",
        "rangeStart": "192.168.0.131",
        "rangeEnd": "192.168.0.131",
        "routes": [
          { "dst": "0.0.0.0/0" }
        ],
        "gateway": "192.168.0.7"
      }
    }'

但无论配置如何,都不会使用指定的 ip 创建 pod。我需要尽快解决这个问题。我怎样才能做到这一点?

4

0 回答 0