1
我在單個豆莢內部部署了2個容器(container-test2和cloudsql-proxy)。kubernetes使用不同的命令創建多個相同圖像的豆莢/部署
container-test2運行一個docker映像,它將[「my_app」,「arg1」,「arg2」]作爲CMD傳遞。我想用不同的參數組合運行這個容器的幾個實例。我也想在單獨的窗格中運行它們,以便我可以在節點上分發它們。我不完全確定如何做到這一點。
我可以成功運行這兩個容器,但我不知道如何使用不同參數進行container-test2複製,並使每個容器都在單獨的容器中啓動。
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]
編輯:解
我解決它通過創建部署配置的多個拷貝到目錄「部署」,修改名稱和命令,然後運行:
kubectl創建-f部署/
有沒有辦法把它放在一個單一的部署規範。例如複製「 - image ...」部分N次,調整「command:...」指令並指定它應該在它自己的pod中運行? – s5s
不,沒有純粹的kubectl。您可以將多個部署規範放在單個文件中,或編寫您自己的解決方案以用於持續集成工作流程等。 –
謝謝,我通過創建部署/目錄並每個莢具有單個文件來解決此問題 – s5s