Calico allocate ip 10.254.0.0 to a pod

Steps to Reproduce (for bugs)

  1. install kubernetes with kubeadm with

kubeadm init --pod-network-cidr=10.128.0.0/9 --service-cidr=10.96.0.0/24 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version=v1.18.3

  1. kubectl create -f https://docs.projectcalico.org/manifests/calico.yaml
  2. join worker nodes with kubeadm join, then label nodes with rack=0/1/2/3 relatively.
  3. delete the default ipv4 pool
  4. create new pools:
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: core-ippool
spec:
  blockSize: 26
  cidr: 10.128.1.0/24
  ipipMode: Always
  natOutgoing: true
  vxlanMode: Never
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: test-ippool
spec:
  blockSize: 24
  cidr: 10.254.0.0/24
  ipipMode: Never
  natOutgoing: false
  nodeSelector: rack == '0'
---
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: test-ippool2
spec:
  blockSize: 24
  cidr: 10.254.1.0/24
  ipipMode: Never
  natOutgoing: false
  nodeSelector: rack == '1'
---
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: test-ippool3
spec:
  blockSize: 24
  cidr: 10.254.2.0/24
  ipipMode: Never
  natOutgoing: false
  nodeSelector: rack == '2'
---
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: test-ippool1
spec:
  blockSize: 24
  cidr: 10.254.3.0/24
  ipipMode: Never
  natOutgoing: false
  nodeSelector: rack == '3'
  1. create a deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-ext
spec:
  replicas: 1
  selector:
     matchLabels:
       app: busybox-ext
  template:
    metadata:
      labels:
        app: busybox-ext
      annotations:
        "cni.projectcalico.org/ipv4pools": "[\"test-ippool\"]"
    spec:
      containers:
        - name: test-container
          image: registry.cn-hangzhou.aliyuncs.com/google_containers/busybox
          command: [ "sh", "-c"]
          args:
          - while true; do
              echo -en '\n';
              printenv MY_NODE_NAME MY_POD_NAME MY_POD_NAMESPACE;
              printenv MY_POD_IP MY_POD_SERVICE_ACCOUNT;
              sleep 100;
            done;
          env:
            - name: MY_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MY_POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: MY_POD_SERVICE_ACCOUNT
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  app: busybox-ext
  1. check ip address for the pod
 [root@k8s-master ~]# kubectl get pods -o wide
 NAME                           READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
 busybox-ext-6854978799-tjqwn   1/1     Running   0          6s    10.254.0.0   k8s-work1   <none>           <none>

Your Environment

[root@k8s-master ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", BuildDate:"2020-06-26T03:47:41Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

[root@k8s-master ~]# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)

[root@k8s-master ~]# calicoctl version
Client Version:    v3.15.0
Git commit:        7987fc57
Cluster Version:   v3.15.1
Cluster Type:      k8s,bgp,kubeadm,kdd