Following this article How to add authorized IP to private GKE cluster using gcloud CLI?, I did not find a way to add IP address to private GKE cluster using gcloud CLI without overriding the existing IPs. Tried below gcloud CLI command :-
gcloud container clusters update CLUSTER_NAME \
--enable-master-authorized-networks \
--master-authorized-networks CIDR1,CIDR2,...
But it is overriding the existing IPs (I had around 15 IPs added before). Is there a way to avoid the overriding and append the IP to the existing list ?
A workaround would be creating a variable to save the current values of the authorized network and another one to save the new ones. Once you have those variables, you may concatenate them and assign them to the update command.
NEW_CIDR=ip/mask,ip/mask
export CLUSTER=clusterName
OLD_CIDR=$(gcloud container clusters describe $CLUSTER --zone zoneName --format json | jq -r '.masterAuthorizedNetworksConfig.cidrBlocks[] | .cidrBlock' | tr '\n' ',')
echo "The existing master authorized networks were $OLD_CIDR"
gcloud container clusters update $CLUSTER --zone zoneName --master-authorized-networks "$OLD_CIDR$NEW_CIDR" --enable-master-authorized-networks