<p>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 .</p>
<p>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</p>
<p>The definition file for pod and service file is as below
pod file</p>
<pre><code>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: [&quot;sleep&quot;]
    args: [&quot;3200&quot;]
    ports:
         - containerPort: 5000
</code></pre>
<p>Service file</p>
<pre><code>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
</code></pre>

Waseem Mir
<p>You're missing <code>apiVersion: v1</code> at the top of the yaml.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: voting-app-pod
  labels:
    name: voting-app-pod
    app: demo-voting-app
spec:
  containers:
  - name: voting-app
    image: mirwasim0/bloomreach
    command: [&quot;sleep&quot;]
    args: [&quot;3200&quot;]
    ports:
         - containerPort: 5000
</code></pre>
<p>Other than that, I tried your pod yaml in a test cluster and it started up fine with no crashloops</p>
<hr />
<p><strong>UPDATE</strong></p>
<p>Removing the sleep command</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: voting-app-pod
  labels:
    name: voting-app-pod
    app: demo-voting-app
spec:
  containers:
  - name: voting-app
    image: mirwasim0/bloomreach
    # command: [&quot;sleep&quot;]
    # args: [&quot;3200&quot;]
    ports:
         - containerPort: 5000
---
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
</code></pre>
<p>Gives me the following crash out in the logs:</p>
<pre><code>$ kubectl logs -f voting-app-pod 
 * Serving Flask app 'app.py' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File &quot;/usr/local/bin/flask&quot;, line 8, in &lt;module&gt;
    sys.exit(main())
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 994, in main
    cli.main(args=sys.argv[1:])
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 600, in main
    return super().main(*args, **kwargs)
  File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 1053, in main
    rv = self.invoke(ctx)
  File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 754, in invoke
    return __callback(*args, **kwargs)
  File &quot;/usr/local/lib/python3.7/site-packages/click/decorators.py&quot;, line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 754, in invoke
    return __callback(*args, **kwargs)
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 849, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 324, in __init__
    self._load_unlocked()
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 350, in _load_unlocked
    self._app = rv = self.loader()
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 406, in load_app
    app = locate_app(self, import_name, name)
  File &quot;/usr/local/lib/python3.7/site-packages/flask/cli.py&quot;, line 260, in locate_app
    __import__(module_name)
  File &quot;/code/app.py&quot;, line 11, in &lt;module&gt;
    cache = redis.Redis(host=os.environ['REDIS_HOST'], port=os.environ['REDIS_PORT'])
  File &quot;/usr/local/lib/python3.7/os.py&quot;, line 681, in __getitem__
    raise KeyError(key) from None
KeyError: 'REDIS_HOST'
</code></pre>
<p>This indicates you've omitted you add the environment variable <code>REDIS_HOST</code>. After trying a few more times, I found there's a few other environments variables you're missing such as <code>REDIS_HOST</code>, <code>REDIS_PORT</code>, <code>USERNAME</code>, <code>PASSWORD</code>. You just need to add those in like this, (and any other environment variables your script requires)</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: voting-app-pod
  labels:
    name: voting-app-pod
    app: demo-voting-app
spec:
  containers:
  - name: voting-app
    image: mirwasim0/bloomreach
    # command: [&quot;sleep&quot;]
    # args: [&quot;3200&quot;]
    ports:
         - containerPort: 5000
    env:
      - name: REDIS_HOST
        value: &quot;127.0.0.1&quot;
      - name: REDIS_PORT
        value: &quot;1234&quot;
      - name: USERNAME
        value: &quot;my-user-name&quot;
      - name: PASSWORD
        value: &quot;my-password&quot;
      ...
      ...
</code></pre>
