How to append new ip in existing authorized network list on google cloud kubernetes cluster

Viewed 86

Right now, I can add my ip using

gcloud container clusters update core-cluster --zone=asia-southeast1-a --enable-master-authorized-networks --master-authorized-networks w.x.y.z/32

but it overrides all the existing authorized networks that was already there.

Is there any way to append the new ip to the existing list of authorized networks?

2 Answers

No. You'll need to first get the current value, append that to the additional value and then update with the new aggregate list.

You could automate what @Gari Singh said using gcloud, jq and tr. See below for doing it with CLI:

NEW_CIDR=8.8.4.4/32
export CLUSTER=test-psp
OLD_CIDR=$(gcloud container clusters describe $CLUSTER --format json | jq -r '.masterAuthorizedNetworksConfig.cidrBlocks[] | .cidrBlock' | tr '\n' ',')
echo "The existing master authorized networks were $OLD_CIDR"
gcloud container clusters update $CLUSTER --master-authorized-networks "$OLD_CIDR$NEW_CIDR" --enable-master-authorized-networks
Related