【问题标题】:kubernetes create multiple pods/deployments of the same image with different commandkubernetes 使用不同的命令创建同一映像的多个 pod/deployments
【发布时间】:2018-03-07 15:36:33
【问题描述】:

我在一个 pod 中部署了 2 个容器(container-test2cloudsql-proxy)。

container-test2 运行一个将 ["my_app", "arg1", "arg2"] 作为 CMD 传递的 docker 映像。我想用不同的参数组合运行这个容器的几个实例。我还想在单独的 pod 中运行它们,以便可以跨节点分发它们。我不完全确定该怎么做。

我可以成功运行这两个容器,但我不知道如何使用不同的参数复制 container-test2 并使每个容器在单独的 pod 中启动。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - image: gcr.io/testing-11111/testology:latest
          name: container-test2
          command: ["my_app", "arg1", "arg2"]
          env:
            - name: DB_HOST
              # Connect to the SQL proxy over the local network on a fixed port.
              # Change the [PORT] to the port number used by your database
              # (e.g. 3306).
              value: 127.0.0.1:5432
            # These secrets are required to start the pod.
            # [START cloudsql_secrets]
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: password
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: username
            # [END cloudsql_secrets]
          resources:
            requests:
              #memory: "64Mi"
              cpu: 0.1
            limits:
              memory: "375Mi"
              cpu: 0.15


        # Change [INSTANCE_CONNECTION_NAME] here to include your GCP
        # project, the region of your Cloud SQL instance and the name
        # of your Cloud SQL instance. The format is
        # $PROJECT:$REGION:$INSTANCE
        # Insert the port number used by your database.
        # [START proxy_container]
        - image: gcr.io/cloudsql-docker/gce-proxy:1.09
          name: cloudsql-proxy
          command: ["/cloud_sql_proxy", "--dir=/cloudsql",
                    "-instances=testing-11111:europe-west2:testology=tcp:5432",
                    "-credential_file=/secrets/cloudsql/credentials.json"]
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
            - name: ssl-certs
              mountPath: /etc/ssl/certs
            - name: cloudsql
              mountPath: /cloudsql
        # [END proxy_container]
          resources:
            requests:
              #memory: "64Mi"
              cpu: 0.1
            limits:
              memory: "375Mi"
              cpu: 0.15

      # [START volumes]
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
        - name: ssl-certs
          hostPath:
            path: /etc/ssl/certs
        - name: cloudsql
          emptyDir:
      # [END volumes]

编辑:解决方案

我通过在目录“deployments”中创建多个部署配置副本来解决它,修改名称和命令然后运行:

kubectl create -f 部署/

【问题讨论】:

    标签: kubernetes google-kubernetes-engine


    【解决方案1】:
    1. 您不能让单个副本使用不同的参数运行,它们不会是“精确副本”中的副本。如果您想使用不同的参数多次运行您的应用程序,则需要使用多个部署。

    2. 复制的容器在它们自己的 Pod 中运行,例如一个部署应该存在三个 Pod,可以扩展到三个复制

    【讨论】:

    • 有没有办法把它放在一个部署规范中。比如复制“-image...”部分N次,调整“command:...”指令并指定它应该在自己的pod中运行?
    • 不,没有纯 kubectl。您可以将多个部署规范放在一个文件中,或者编写自己的解决方案以用于持续集成工作流程等。
    • 谢谢,我暂时解决了这个问题,方法是创建一个 deployments/ 目录并为每个 pod 设置一个文件
    猜你喜欢
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2020-08-07
    • 2021-12-07
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多