kops create cluster inside existing AWS vpc and subnets

6/21/2018

I am having a trouble creating a kubernets using kops inside existing AWS vpc and subnets. I have an existing vpc with the following CIDR blocks:

IPv4 CIDR: 10.10.16.0/20

And in that VPC I have my subnets with their assigned CIDR blocks:

SubnetDatabaseA: 10.10.23.0/24

SubnetDatabaseB: 10.10.24.0/24

SubnetDatabaseC: 10.10.20.0/24

And so on...

when trying to create the cluster using kops I get this error:

 error running task "Subnet/ap-southeast-2a.clusters.dev1.k8s.local" (9m58s remaining to succeed): error creating subnet: InvalidSubnet.Conflict: The CIDR '10.10.18.0/23' conflicts with another subnet
        status code: 400, request id: 252367d1-d693-47b9-a6c5-a44908a0f6f7

Which means that one of my subnets is already using that IP range.

How can I assign kops to use a specific CIDR of my choice?

Because I can see that every time I try to create the cluster it assigns a different CIDR (example- CIDR 10.10.18.0/23)?

-- Shachar Hamuzim Rajuan
kops
kubernetes

1 Answer

8/14/2018
kops create cluster --help
--subnets stringSlice                  Set to use shared subnets
--vpc string                           Set to use a shared VPC

See following

 kops create cluster --name=${CLUSTER_NAME} --vpc=vpc-1010af11 --subnets=subnet- 000e123a,subnet-123b456,subnet-888c9991 --master-zones=${ZONES} --zones=${ZONES}  --networking=weave

So, if you pass subnet ids, kops doesn't create new CIDR, instead, it will use provided subnet ids and corresponding CIDRs. refer following.

  subnets:
- cidr: 92.145.123.0/26
  id: subnet- 000e123a
  name: us-east-1a
  type: Public
  zone: us-east-1a
- cidr: 92.145.123.64/26
  id: subnet-123b456
  name: us-east-1b
  type: Public
  zone: us-east-1b
- cidr: 92.145.123.128/26
  id: subnet-888c9991
  name: us-east-1c
  type: Public
  zone: us-east-1c

Or you can edit the cluster with kops edit cluster $CLUSTER_NAME after running kops create cluster without --subnets flag and update the subnets section as seen above.

Reference: https://github.com/kubernetes/kops/blob/master/docs/cli/kops_create_cluster.md

-- f-society
Source: StackOverflow