简体   繁体   English

如何将 VPC 子网(GCP)分配给 kubernetes 集群?

[英]How to assign VPC subnet(GCP) to kubernetes cluster?

I have VPC setup on Google Cloud which has 192.0.0.0/24 as subnet in which I am trying to setup k8s cluster for following servers,我在 Google Cloud 上设置了 VPC,它有 192.0.0.0/24 作为子网,我正在尝试为以下服务器设置 k8s 集群,

VM   :  VM NAME     : Internal IP     
VM 1 : k8s-master   : 192.24.1.4
VM 2 : my-machine-1 : 192.24.1.1
VM 3 : my-machine-2 : 192.24.1.3
VM 4 : my-machine-3 : 192.24.1.2

Here k8s-master would act as a master and all other 3 machines would act as nodes.这里 k8s-master 将充当主节点,所有其他 3 台机器将充当节点。 I am using following command to initilize my cluster.我正在使用以下命令来初始化我的集群。

sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ( need to change this to vpc subnet) --apiserver-advertise-address=0.0.0.0 --apiserver-cert-extra-sans=k8s-master-external-ip 

I am using flannel for which I am using following command to setup network for my cluster,我正在使用法兰绒,我正在使用以下命令为我的集群设置网络,

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Now whenever I am deploying a new pod, k8s is assigning IP from 10.244.0.0/16 to that pod which is not accessible from my eureka as my eureka server is running on Google Cloud VPC cidr.现在,每当我部署一个新的 pod 时,k8s 都会将 IP 从 10.244.0.0/16 分配给该 pod,因为我的 eureka 服务器正在 Google Cloud VPC cidr 上运行,所以我的 eureka 无法访问该 pod。

I want to configure k8s such that it will use vpc subnet IP ( internal IP of the machine where pod is deployed ).我想配置 k8s,使其使用 vpc 子网 IP (部署 pod 的机器的内部 IP )。

I even tried to manually download kube-flannel.yml and change cidr to my subnet but that did not solve my problem.我什至尝试手动下载 kube-flannel.yml 并将 cidr 更改为我的子网,但这并没有解决我的问题。

Need help to resolve this.需要帮助来解决这个问题。 Thanks in advance.提前致谢。

Kubernetes needs 3 subnets. Kubernetes 需要 3 个子网。

1 Subnet for the nodes (this would your vpc subnet 192.168.1.0/24) 1 Subnet for your pods.节点的 1 个子网(这将是您的 vpc 子网 192.168.1.0/24) 1 个 pod 的子网。 Optionally 1 Subnet for Services.可选 1 个服务子网。

These subnets cannot be the same they have to be different.这些子网不能相同,它们必须不同。

I believe what's missing in your case are routes to make the pods talk to each other.我相信您的案例中缺少的是使豆荚相互交谈的路线。 Have a look at this guide for setting up the routes you need查看本指南以设置您需要的路线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM