如何将一个pod配置嵌入另一个pod

时间:2017-11-16 04:42:38

标签: kubernetes

我比较了两个pod与容器之间的通信场景--link.I有一个兔子mq容器和一个使用它的应用程序。

现在,我们如何在kubernetes中执行相同操作,其中应用程序依赖于rabbitmq。

下面是我的myapplication的replicationcontroller的代码,它是apache airavata:

airavata-全rc.yml

apiVersion: v1

kind: ReplicationController

metadata:

    name: airavata-all-rc

    labels:

      app : airavata-all-sc
spec:

  replicas: 5

  selector:

    app: airavata-all

  template:

    metadata:

      labels:

        app: airavata-all

    spec:

      containers:

      - name: airavata-all

        image: satyamsah/airavata-all

        ports:

        - containerPort: 8080

以下是我的服务版代码,与myache应用程序相同,即apache airavata:

airavata-全svc.yml

apiVersion: v1

kind: Service

metadata:

  name: airavata-svc

  labels:

    app: airavata-all-svc

spec:

  type: NodePort

  ports:

  - port: 8080

    nodePort: 30002

    protocol: TCP

  selector:

    app: airavata-all

以下是rabbitmq依赖:rmq-rc.yml

apiVersion: v1 
kind: ReplicationController
metadata:
  name: rmq-rc
spec:
  selector:
    app: rmq
  replicas: 1 
  template: 
    metadata:    
      labels:
        app: rmq
    spec:
      containers:
      - name: rmq
        image: rabbitmq:3-management
        env:
        - name: RABBITMQ_DEFAULT_USER
          value: "airavata"
        - name: RABBITMQ_DEFAULT_PASS
          value: "airavata"
        ports: 
        - containerPort: 5672
        - containerPort: 15672

如何让这两个应用程序相互通信?

2 个答案:

答案 0 :(得分:0)

将RabbitMQ依赖项公开为Kubernetes服务,这将为其提供一致的IP地址。您可以使用其他pod中的IP,或使用服务的DNS名称,格式为:my-svc.my-namespace.svc.cluster.local。

另外,请考虑从Replication Controller迁移到ReplicaSet或Deployment。请参阅:https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/

答案 1 :(得分:0)

我认为最简单的方法是创建一个rabbitmq服务并通过ENV变量链接它。

创建服务yaml:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  labels:
    app: rabbitmq
spec:
  ports:
  - port: 5672
    name: amqp
  - port: 4369
    name: epmd
  - port: 25672
    name: rabbitmq-dist
  clusterIP: None
  selector:
    app: rabbitmq

然后代替复制控制器创建部署或有状态集 对于Rabbitmq,这取决于这项服务:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: rabbitmq
spec:
  serviceName: "rabbitmq"
  replicas: 1
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - name: rabbitmq
    ....

现在让你的airavata通过ENV获取Rabbitmq链接。并将ENV变量添加到其yaml:

....
env:
  - name: RABBITMQ_HOST
    value: "rabbitmq"
....