我在单个 pod 中部署了 2 个容器( container-test2 和 cloudsql-proxy )。
容器测试 2 运行一个 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/
最佳答案
关于kubernetes 使用不同的命令为同一个镜像创建多个 pods/deployments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46425997/