I have a Deployment object with Container A and Container B in OpenShift.
The requirement here is that whenever container B exits, container A should follow or otherwise the entire pod should be replaced.
Is there any way to achieve this?
This is my YAML.
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-redis-bundle
labels:
app: app-redis-bundle
spec:
replicas: 1
selector:
matchLabels:
app: app-redis-bundle
template:
metadata:
labels:
app: app-redis-bundle
spec:
containers:
- name: cache-store-2
image: redis
resources:
limits:
cpu: 500m
memory: 1500Mi
requests:
cpu: 250m
memory: 1Gi
ports:
- containerPort: 6379
livenessProbe:
tcpSocket:
port: 6379
- name: app-server-2
image: 'app:latest'
resources:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
ports:
- containerPort: 8443
livenessProbe:
tcpSocket:
port: 8443
imagePullSecrets:
- name: mysecret
2
Answers
Thanks for your comments.
The issue is resolved now.
Allow me to elaborate it and explain the solution.
Problem Statement
I was needed to deploy a Pod in OpenShift with 2 containers A and B in a manner such that whenever container A terminates, container B should automatically kill itself as well.
Initially, my approach was to run a termination script in container B from container A. However, this approach didn't help.
Solution
Using a liveness probe to send a TCP Socket connection from B to A on the running port did the magic and now B is terminating as soon as A exits.
Job done.
Below is the working yaml.
both containers use the same ephemeral network, which means container A can communicate with container B on "localhost:port".
This multi-container pod is explained here in a clear way.