<p>I am running a sample webapp python in Kubernetes.
I am not able to figure out how I make use of probes here.</p>
<ol>
<li><p>I want app to recover from broken states by automatically restarting pods</p>
</li>
<li><p>Route the traffic to the healthy pods only.</p>
</li>
<li><p>Make sure the database is up and running before the application (which in my case is Redis).</p>
</li>
</ol>
<p>I have understanding of probes but not sure how/what values exactly to look for</p>
<p>My definition file:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
     env: production
     app: frontend
spec:
  selector:
    matchLabels:
      env: production
      app: frontend
  replicas: 1
  template:
    metadata:
      name: myapp-pod 
      labels:
        env: production
        app: frontend
    spec:
      containers:
      - name: myapp-container
        image: myimage:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 5000
</code></pre>
<p>Now I am doing something like this</p>
<pre><code>        readinessProbe:
          httpGet:
            path: /
            port: 5000
          initialDelaySeconds: 20
          periodSeconds: 5
        livenessProbe:
        httpGet:
          path: /
          port: 5000
        intialDelaySeconds: 10
        periodSeconds: 5
</code></pre>

<p>You need to define both</p>
<ul>
<li><code>readinessProbe</code>: allowing to tell whether your <code>Deployment</code> is ready to serve traffic at any point of time during its lifecycle. This configuration item can support different command but in your case, this would be an <code>httpGet</code> matching and endpoint that you would implement in your web-app (most modern stack define the endpoints by default so check check the documentation of whatever framework you are using). Note that the endpoint handler would need to check the <strong>readiness</strong> of any needed dependency, in your case you would need to check if <code>http[s]://redis-host:redis-port</code> responds with success</li>
<li><code>livenessProbe</code>: allowing for the control plane to check continuously your pods health and to decide on actions needed to get the cluster to the desired state rolling out any pods failing to report being alive. This probe support different definitions as well and as for the <code>readinessProbe</code> most modern framework offer endpoints responding to such request by default</li>
</ul>
<p>Here down you can see a sample of both probes, for which you would have two respective HTTP endpoints within your web application:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
     env: production
     app: frontend
spec:
  selector:
    matchLabels:
      env: production
      app: frontend
  replicas: 1
  template:
    metadata:
      name: myapp-pod 
      labels:
        env: production
        app: frontend
    spec:
      containers:
      - name: myapp-container
        image: myimage:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 5000
      readinessProbe:
        httpGet:
          path: /health
          port: 5000
      livenessProbe:
        httpGet:
          path: /health
          port: 5000
</code></pre>
