Kubernetes中的静态传出IP [英] Static outgoing IP in Kubernetes
问题描述
我在google云(GKE)和aws(RDS)中运行MySQL服务器运行k8s群集。豆荚需要连接到RDS,它只允许来自特定IP的连接。我怎样才能配置出站流量有一个静态IP?
我有同样的问题连接到一个sftp服务器从一个荚。
为了解决这个问题,首先您需要创建一个外部IP地址:
gcloud compute addresses create {{EXT_ADDRESS_NAME} } --region {{REGION}}
然后,我想你的pod被分配给你的默认值池节点群集。
提取您的默认池节点名称:
gcloud计算实例列表| awk'{print $ 1}'| grep default-pool
清除虚拟机实例的默认外部IP:
gcloud计算实例delete-access-config {{VM_DEFAULT-POOL_INSTANCE}} --access-config-name external-nat
$ c $
<$ c $
添加您之前创建的外部静态ip: c> gcloud compute instances add-access-config {{VM_DEFAULT-POOL_INSTANCE}} --access-config-name external-nat --address {{EXT_ADDRESS_IP}}
$ b $ p如果您的Pod未连接到默认池节点,请不要忘记使用nodeSelector选择它: nodeSelector:
cloud.google.com/gke-nodepool:{{NODE_NAME}}
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 outgoing traffic to have a static IP?
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 }}
这篇关于Kubernetes中的静态传出IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!