I am very new to k8s
and docker
. But I have task on k8s. Now I stuck with a use case. That is:
If a container is busy with requests. Then incoming request should redirect to another container.
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: twopoddeploy
namespace: twopodns
spec:
selector:
matchLabels:
app: twopod
replicas: 1
template:
metadata:
labels:
app: twopod
spec:
containers:
- name: secondcontainer
image: "docker.io/tamilpugal/angmanualbuild:latest"
env:
- name: "PORT"
value: "24244"
- name: firstcontainer
image: "docker.io/tamilpugal/angmanualbuild:latest"
env:
- name: "PORT"
value: "24243"
service.yaml
apiVersion: v1
kind: Service
metadata:
name: twopodservice
spec:
type: NodePort
selector:
app: twopod
ports:
- nodePort: 31024
protocol: TCP
port: 82
targetPort: 24243
From deployment.yaml
, I created a pod with two containers with same image. Because, firstcontainer
is not reachable/ busy, then secondcontainer
should handles the incoming requests. This our idea and use case. So (only for checking our use case) I delete firstcontainer
using docker container rm -f id_of_firstcontainer
. Now site is not reachable until, docker recreates the firstcontainer
. But I need k8s should redirects the requests to secondcontainer
instead of waiting for firstcontainer
.
Then, I googled about the solution, I found Ingress
and Liveness - Readiness
. But Ingress
does route the request based on the path instead of container status. Liveness - Readiness
also recreates the container. SO
also have some question and some are using ngix
server. But no luck. That why I create a new question.
So my question is how to configure the two containers to reduce the downtime?
what is keyword for get the solution from the google to try myself?
Thanks,
Pugal.