I am trying to build and deploy an image in Kubernetes, but when I deploy, it failed with crash loop error, I did add sleep time in that so now it is not failing, but the application is not accessible via the service .
I tried to check pod logs as well but there is no logs at all.
Any Kubernetes expert can help me solve this please
there is a dependency of redis but the basic is not working
Image that I am using is at
The definition file for pod and service file is as below
pod file
apiVersion: v1
kind: Pod
metadata:
name: voting-app-pod
labels:
name: voting-app-pod
app: demo-voting-app
spec:
containers:
- name: voting-app
image:
command: ["sleep"]
args: ["3200"]
ports:
- containerPort: 5000
Service file
apiVersion: v1
kind: Service
metadata:
name: voting-service
labels:
name: voting-service
app: demo-voting-app
spec:
ports:
- port: 80
protocol: TCP
targetPort: 5000
type: LoadBalancer
selector:
name: voting-app-pod
app: demo-voting-app
2
Answers
You’re missing
apiVersion: v1
at the top of the yaml.Other than that, I tried your pod yaml in a test cluster and it started up fine with no crashloops
UPDATE
Removing the sleep command
Gives me the following crash out in the logs:
This indicates you’ve omitted you add the environment variable
REDIS_HOST
. After trying a few more times, I found there’s a few other environments variables you’re missing such asREDIS_HOST
,REDIS_PORT
,USERNAME
,PASSWORD
. You just need to add those in like this, (and any other environment variables your script requires)I see some environment variables are mandatory to startup the service: