Static outgoing IP in Kubernetes

前端 未结 4 926
一整个雨季
一整个雨季 2020-12-04 21:40

I run a k8s cluster in google cloud (GKE) and a MySQL server in aws (RDS). Pods need to connect to RDS which only allows connections from certain IP. How can I configure out

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 22:20

    I had the same problem to connect to a sftp server from a Pod. To solve this, first you need to create an external IP address:

    gcloud compute addresses create {{ EXT_ADDRESS_NAME }} --region {{ REGION }}
    

    Then, I suppose that your pod is assigned to your default-pool node cluster. Extract your default-pool node name:

    gcloud compute instances list | awk '{ print $1 }' | grep default-pool
    

    Erase default external ip of the vm instance:

    gcloud compute instances delete-access-config {{ VM_DEFAULT-POOL_INSTANCE }} --access-config-name external-nat
    

    Add your external static ip created before:

    gcloud compute instances add-access-config {{ VM_DEFAULT-POOL_INSTANCE }} --access-config-name external-nat --address {{ EXT_ADDRESS_IP }}
    

    If your Pod is not attached to the default-pool node, don't forget to select it with a nodeSelector:

    nodeSelector:
        cloud.google.com/gke-nodepool: {{ NODE_NAME }} 
    

提交回复
热议问题