[英]Can I reach a container by it's hostname from another container running on another node in Kubernetes?
I believe my question is pretty straightforward. 我相信我的问题很简单。 I'm doing my prerequisites to install Kubernetes cluster on bare metal.
我正在做我在裸机上安装Kubernetes集群的先决条件。
Let's say I have: 比方说我有:
master - hostname for Docker DB container which is fixed on first node master - 在第一个节点上修复的Docker DB容器的主机名
slave - hostname for Docker DB container which is fixed on second node slave - Docker DB容器的主机名,它固定在第二个节点上
Can I communicate with master from any container (app, etc.) in a cluster regardless it's running on the same node or not? 我是否可以从群集中的任何容器(应用程序等)与master通信,无论它是否在同一节点上运行?
Is this a default behaviour? 这是默认行为吗? Or anything additional should be done?
还是应该做任何额外的事情?
I assume that I need to setup hostname
parameter in YAML or JSON file so Kubernetes is aware what the hostname is. 我假设我需要在YAML或JSON文件中设置
hostname
参数,以便Kubernetes知道主机名是什么。
Probably this is not the factor, but I plan to use Kubespray installation method so it gets Calico networking for k8s. 可能这不是因素,但我打算使用Kubespray安装方法,因此它可以获得k8s的Calico网络。
Many thanks 非常感谢
Yes, 是,
You can access and communication from any container in a namespace
via hostname. 您可以通过主机名从
namespace
任何容器访问和通信。
Here is an example about Kubernetes Service
configure: 以下是Kubernetes
Service
配置的示例:
---
apiVersion: v1
kind: Service
metadata:
name: master
labels:
name: master
namespace: smart-office
spec:
ports:
- port: 5672
name: master
targetPort: 5672
selector:
name: master
Deployment
configure: Deployment
配置:
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: master
labels:
name: master
namespace: smart-office
spec:
replicas: 1
template:
metadata:
labels:
name: master
annotations:
prometheus.io/scrape: "false"
spec:
containers:
- name: master
image: rabbitmq:3.6.8-management
ports:
- containerPort: 5672
name: master
nodeSelector:
beta.kubernetes.io/os: linux
And from other services, for eg your slaver
.env
will be: 而从其他服务,例如你的
slaver
.env
将是:
AMQP_HOST=master <---- The hostname
AMQP_PORT=5672
AMQP_USERNAME=guest
AMQP_PASSWORD=guest
AMQP_HEARTBEAT=60
It's will work inside Cluster even if you not publish External IP. 即使您没有发布外部IP,它也可以在集群内部工作。
Hope this can help you. 希望这可以帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.