Kubernetes-服务之间的通信 [英] Kubernetes - communication between services

查看:98
本文介绍了Kubernetes-服务之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究kubernetes集群.群集工作正常. 我需要在不使用代理的情况下在服务之间建立通信. 例如,我有以下服务:

I'm currently working on a kubernetes cluster. Cluster is working properly. I need to establish communication between services without using proxy. For example I have services below:

  1. 工人
  2. app1
  3. app2
  4. app3

工作人员需要直接通过SSH登录到应用程序容器并执行一些命令. 在docker-compose文件中,使用链接,然后使用ssh app1,ssh app2可以轻松实现. 如何在Kubernetes中做到这一点?

Worker needs to login to app containers directly via SSH and do some commands. In docker-compose file it was easy by using links and then ssh app1, ssh app2. How to do it in Kubernetes ?

推荐答案

有伪代码,

kind: Service
apiVersion: v1
metadata:
  name: worker
  labels:
    app: worker
spec:
  selector:
    app: worker
  ports:
  - protocol: TCP
    port: 22
    targetPort: 22
  type: NodePort 
---
kind: Service
apiVersion: v1
metadata:
  name: app1
  labels:
    app: app1
spec:
  selector:
    app: app1
  ports:
  - protocol: TCP
    port: 22
    targetPort: 22
  type: ClusterIP 
---
kind: Service
apiVersion: v1
metadata:
  name: app2
  labels:
    app: app2
spec:
  selector:
    app: app2
  ports:
  - protocol: TCP
    port: 22
    targetPort: 22
  type: ClusterIP 

然后,在工人上

ssh app1
ssh app2

这篇关于Kubernetes-服务之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆