Udit Sarin
Udit Sarin

Reputation: 59

Different pod CIDR for different deployment Kubernetes

I am working on a project where I need to launch a particular deployment with a specific CIDR range. Is there any way i can do this ?

I need these CIDR ranges for different deployments.

For example:

  1. Deployment 1 - Have 10 replicas running with CIDR 10.10.10.0/24

  2. Deployment 1 - Have 10 replicas running with CIDR 10.10.11.0/24

Upvotes: 0

Views: 183

Answers (1)

Udit Sarin
Udit Sarin

Reputation: 59

This can be achieved by using Calico's IPPool.

  1. install kubernetes with calico.

  2. you create a IPPool, copy the below Yaml content in a file.

apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: pool1
spec:
  cidr: 192.168.0.0/18
  ipipMode: Never
  natOutgoing: true
  disabled: false
  nodeSelector: all()

and apply this above yaml using the following command

calicoctl create -f pool1.yaml

Now deploy any service like this

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        "cni.projectcalico.org/ipv4pools": "[\"192.168.0.0/18\"]"
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Apply the above yaml using

kubectl apply -f nginx.yaml

Check the ip of running pods using

kubectl get pods -o wide

Upvotes: 1

Related Questions