We can add a liveness/rediness probe in our kubernetes deployment assuming we have a rest service to call. 

For this to work, we need an endpoint that will respond with a 200 OK when called.


In the following example, we have a container containing an endpoint the the following specifications:

  • response: 200 OK
  • URL:  /monitor/health


To configure this in our kubernetes deployment, we will need to add the following:


service.yaml

apiVersion: v1
kind: Service
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080


deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myapp:1.0.0-SNAPSHOT
...
          readinessProbe:
            httpGet:
              path: /monitor/health
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /monitor/health
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 5



  • No labels