简体   繁体   English

如何使用内部网络设置 k8s IP?

[英]How to setup k8s IP's with internal network?

Recently I decided to set up a k8s cluster on a few VM's.最近我决定在几个虚拟机上建立一个 k8s 集群。
I worked with K8s in the past but it's a long time since.我过去使用过 K8s,但已经很久了。
One of the things I want to run in the cluster is a web server with Nginx.我想在集群中运行的其中一件事是带有 Nginx 的 web 服务器。

I have 3 VM's 1 master, 2 workers.我有 3 个 VM 的 1 个主人,2 个工人。 They have each an external and internal IP.它们各有一个外部和内部 IP。

I was wondering how I should set up k8s.我想知道我应该如何设置k8s。
So I would want to use the external IP as my cluster IP but the nodes should communicate with the internal network.所以我想使用外部 IP 作为我的集群 IP 但节点应该与内部网络通信。

How do I need to configure this?我需要如何配置它?
I guess I need one of these options of the kubeadm init command but I am not sure?我想我需要kubeadm init命令的这些选项之一,但我不确定?

--control-plane-endpoint
--apiserver-advertise-addres

If Someone could explain with an example that would be great!如果有人可以用一个例子来解释,那就太好了!

I hope i understood you correctly, if not please update me.我希望我理解正确,如果没有请更新我。

So I would want to use the external IP as my cluster IP but the nodes should communicate with the internal network.所以我想使用外部 IP 作为我的集群 IP 但节点应该与内部网络通信。

First of all your external IP need to be首先你的外部 IP 需要

apiVersion: v1
kind: Service
....
type: LoadBalancer

but the nodes should communicate with the internal network但节点应该与内部网络通信

For this purpose, you should use StaefulSet instead of deployment.为此,您应该使用StaefulSet而不是部署。

The main difference from your perspective (in order to answer your question) is the StatefulSet attaches a unique FQDN to your pod and this address is guaranteed to be "attached" to the pod when you reschedule it.从您的角度来看(为了回答您的问题)的主要区别是StatefulSet将唯一的 FQDN 附加到您的 pod,并且当您重新安排它时,该地址保证“附加”到 pod。

So you should have something like this:所以你应该有这样的东西:

  • nginx - Exposed via LoadBalancer (external IP) nginx - 通过 LoadBalancer 暴露(外部 IP)
  • apps - StatefulSet apps that have a unique IP and the Nginx can communicate with them using this IP.应用程序 - 具有唯一 IP 和 Nginx 的 StatefulSet 应用程序可以使用此 IP 与它们通信。

在此处输入图像描述

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

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