Wordpress+Mysql deployment don't get IP address from another pool

6/17/2021

My deployment is about Wordpress and MYsql. I already defined a new pool and a new namespace and I was trying to make that my pods get an ip address from this new pool defined but they never get one.

My namespace file yaml

apiVersion: v1
kind: Namespace
metadata:
  name: produccion
  annotations:
    cni.projectcalico.org/ipv4pools: ippool

my pool code

calicoctl create -f -<<EOF
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
   name: ippool
spec:
   cidr: 192.169.0.0/24
   blockSize: 29
   ipipMode: Always
   natOutgoing: true
EOF

My mysql deployment is

apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql   
  namespace: produccion
  labels:                 
    app: wordpress
spec:
  ports:
    - port: 3306
      targetPort: 3306
      nodePort: 31066
  selector:
    app: wordpress
    tier: mysql
  type: NodePort
---
apiVersion:  apps/v1
kind: Deployment
metadata:
  name: wordpress-mysql
  namespace: produccion
  annotations:
    cni.projectcalico.org/ipv4pools: ippool
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: mysql
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: PASS
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage 
          mountPath: "/var/lib/mysql"
      volumes:
      - name: mysql-persistent-storage 
        persistentVolumeClaim:
          claimName: mysql-pv-claim

My wordpress deployment

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  namespace: produccion
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
      nodePort: 30999
  selector:
    app: wordpress
    tier: frontend
  type: NodePort
---
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: wordpress
  namespace: produccion
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress
        name: wordpress
        env:
        - name: WORDPRESS_DB_NAME
          value: wordpress
        - name: WORDPRESS_DB_HOST
          value: IP_Address:31066
        - name: WORDPRESS_DB_USER
          value: root
        - name: WORDPRESS_DB_PASSWORD
          value: PASS
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: "/var/www/html"          
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wordpress-persistent-storage

Additionally, I have also two PV yaml file for each service (mysql and wordpress).

When I execute the Kubectl of any deployment, they stay on ContainerCreating and the IP column stay on none.

produccion             wordpress-mysql-74578f5d6d-knzzh             0/1     ContainerCreating   0          70m    <none>           dockerc8.tecsinfo-ec.com 

If I check this pod I get the next errors:

Normal   Scheduled               88s                             default-scheduler  Successfully assigned produccion/wordpress-mysql-74578f5d6d-65jvt to dockerc8.tecsinfo-ec.com
  Warning  FailedCreatePodSandBox  <invalid>                       kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "cdb1460246562cac11a57073ab12489dc169cb72aa3371cb2e72489544812a9b" network for pod "wordpress-mysql-74578f5d6d-65jvt": networkPlugin cni failed to set up pod "wordpress-mysql-74578f5d6d-65jvt_produccion" network: invalid character 'i' looking for beginning of value
  Warning  FailedCreatePodSandBox  <invalid>                       kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "672a2c35c2bb99ebd5b7d180d4426184613c87f9bc606c15526c9d472b54bd6f" network for pod "wordpress-mysql-74578f5d6d-65jvt": networkPlugin cni failed to set up pod "wordpress-mysql-74578f5d6d-65jvt_produccion" network: invalid character 'i' looking for beginning of value
  Warning  FailedCreatePodSandBox  <invalid>                       kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "de4d7669206f568618a79098d564e76899779f94120bddcee080c75f81243a85" network for pod "wordpress-mysql-74578f5d6d-65jvt": networkPlugin cni failed to set up pod "wordpress-mysql-74578f5d6d-65jvt_produccion" network: invalid character 'i' looking for beginning of value

I was using some guides from Internet like this one: https://www.projectcalico.org/calico-ipam-explained-and-enhanced/ but even this doesn't work on my lab.

I am pretty new using Kubernetes and I don't know what else to do or check.

-- MaryStadhes
calico
cni
kubernetes
mysql
wordpress

1 Answer

6/17/2021

Your error is due to invalid values in the YAML, according to the Project Calico documentation here: Using Kubernetes annotations

You will need to provide a list of IP pools as the value in your annotation instead of a single string. The following snippet should work for you.

cni.projectcalico.org/ipv4pools: "[\"ippool\"]"
-- Tanuj Ravi Rao
Source: StackOverflow