kubernetes 使用不同的命令为同一个镜像创建多个 pods/deployments

s5s*_*s5s 6 kubernetes google-kubernetes-engine

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

container-test2运行一个 docker 镜像,它将 ["my_app", "arg1", "arg2"] 作为 CMD 传递。我想用不同的参数组合运行这个容器的几个实例。我还想在单独的 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]
Run Code Online (Sandbox Code Playgroud)

编辑:解决方案

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

kubectl create -f 部署/

Sim*_*sar 3

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

  2. 复制的容器在自己的 Pod 中运行,例如,对于扩展到三个复制的部署,应该存在三个 Pod