kubernetes使用不同的命令创建同一图像的多个pod /部署

时间:2017-09-26 12:02:43

标签: kubernetes google-kubernetes-engine

我在一个pod中部署了2个容器( container-test2 cloudsql-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]

编辑:解决方案

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

  

kubectl create -f deployments /

1 个答案:

答案 0 :(得分:1)

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

  2. 复制的容器在它们自己的Pod中运行,例如部署时应该有三个Pod可以扩展为三次重复