I have a deployment with 2 containers inside a single pod (container-test2 and cloudsql-proxy).
container-test2 runs a docker image which passes ["my_app", "arg1", "arg2"] as CMD. I would like to run several instances of this container with different argument combinations. I would also like to run them in separate pods so that I can distribute them across nodes. I am not entirely sure how to do this.
I can successfully run the two containers but I don't know how to make container-test2 replicate with different arguments and make each container start inside an individual 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]
EDIT: Solution
I solved it by creating multiple copies of the deployment config into directory "deployments", amending the names and command and then running:
kubectl create -f deployments/
Kubernetes Multiple Containers in a POD ^ This is where a Multi Container Pod comes in. Thus, when an application needs several containers running on the same host, the best option is to make a Multi Container (Pod) with everything you need for the deployment of the application.
Creating a pod. Multi-container pods must be created with the create command. Properties are passed to the command as a YAML- or JSON-formatted configuration file. The create command can be used to create a pod directly, or it can create a pod or pods through a Deployment .
In a pre-container world, they would have run on the same physical or virtual machine. Pods are tied to the Node where they are deployed and remain there until termination (according to restart policy) or deletion. In case of a Node failure, new identical Pods will be deployed on other available Nodes.
A Pod can communicate with another Pod by directly addressing its IP address, but the recommended way is to use Services. A Service is a set of Pods, which can be reached by a single, fixed DNS name or IP address. In reality, most applications on Kubernetes use Services as a way to communicate with each other.
You can not make individual replicas run with different arguments, they would not be replicas as in "exact copy". If you want to run your application multiple times with different arguments, you need to use multiple deployments.
The containers of a replication run in their own Pod, e.g. there should be three Pods existing for a Deployment scaled to three replications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With