<p>I am trying to set a <code>readinessprobe</code> and a <code>livenessprobe</code> in <code>kubernetes</code> using <code>yaml</code> and <code>minikube</code></p>

<p>My app is exposed and working perfectly, but when I try <code>&lt;ip&gt;:&lt;port&gt;/healthz</code> it says </p>

<blockquote>
  <p>Cannot GET /healthz</p>
</blockquote>

<p>This is my <code>server.js</code> running with a <code>GET</code> request to check the <code>liveness</code> and <code>readiness</code></p>

<pre><code>'use strict';

const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =&gt; {
  res.send('Hello world\n');
});

// App
const app = express();
app.get('/healthz', (req, res) =&gt; {
  res.send('fine');
});

app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
</code></pre>

<p>and this is my <code>deployment.yaml</code> file </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
        name: node-web-app
spec:
  replicas: 2
  selector:
    matchLabels:
            name: node-web-app
  template:
    metadata:
      labels:
        # you can specify any labels you want here
              name: node-web-app
    spec:
      containers:
      - name: node-web-app
        # image must be the same as you built before (name:tag)
        image: banuka/node-web-app
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
        imagePullPolicy: Never
      terminationGracePeriodSeconds: 60
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
---
kind: Service
apiVersion: v1
metadata:
  labels:
    # these labels can be anything
    name: node-web-app-clusterip
  name: node-web-app-clusterip
spec:
  selector:
    name: node-web-app
  ports:
    - protocol: TCP
      port: 80
      # target is the port exposed by your containers (in our example 8080)
      targetPort: 8080
---
kind: Service
apiVersion: v1
metadata:
  labels:
    name: node-server-nodeport
  name: node-server-nodeport
spec:
  # this will make the service a NodePort service
  type: NodePort
  selector:
    name: node-web-app
  ports:
    - protocol: TCP
      # new -&gt; this will be the port used to reach it from outside
      # if not specified, a random port will be used from a specific range (default: 30000-32767)
      nodePort: 32555
      port: 80
      targetPort: 8080

</code></pre>

<p>But it is not working, and how can I point the <code>livenessprobe</code> pod to my deployment so it I can get the health of my pods/deployment.</p>

BhagyaKolitha Jayalath
<p>Try placing the following snippet in the spec field of your deployment file -</p>

<pre><code>  containers:
  - image: banuka/node-web-app
    name: node-web-app
    command: ["node"]
    args: ["server.js"]
    ports:
    - containerPort: 8080
    stdin: true
    tty: true
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 10
      periodSeconds: 5
      timeoutSeconds: 2
</code></pre>

<hr>

<p>This will give a http get request to container's IP address and if the response returned is like 200 or 300 then it will mark it successful</p>
