c4i-web
c4i-web
c4i-web
c4i-web
  • Home
  • About Us
    • Our Team
  • Services
    • Mobile Application Development
      • iPhone apps Development
      • Android Apps Development
      • Hire Android Developer
      • iPad application development
    • Cloud Based Application Development
    • Web Development
  • Solutions
    • Cloud Migration
    • Data Center
    • Big Data Analytics
    • Educational Solutions
  • Technologies
    • Java
    • Internet of Things
    • Cloud Computing
    • Data Science
  • Careers
    • Open Positions
  • Blogs
    • Blog

      • Technology
      • SEO
      • Social Media
  • Contact

HTTP Liveness and Readiness Probe in Kubernetes Deployment

Home » Technology » HTTP Liveness and Readiness Probe in Kubernetes Deployment

Liveness and Readiness probes are required in Kubernetes to prevent deadlock of your application deployed and zero missing request while pod is initializing. When probe is configured in deployment, each pod will go through probe conditions.

Liveness and readiness probes will be applicable to new pod which is created by horizontal pod autoscaling (hpa)

We are going to learn how to configure probes in kubernetes deployment:

Liveness probe: It will take care of the container when it is in deadlock or application not running by restarting container
Readiness probe: It will take care of the pod when to join the service to serve traffic

Prerequisite:

1) kubectl cli should be installed in your local
2) Connect to the kubernetes cluster
3) /health API should be enabled in application
4) Configmaps related to deployment should be deployed before deployment

Step1:

Configure the liveness and readiness probe in the deployment yaml

Liveness probe:

livenessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 3
  periodSeconds: 3

Liveness probe should be configured under template.spec.containers section

Readiness probe:

readinessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 3
  periodSeconds: 3

Readiness probe configuration is similar to liveness probe and should be configured under template.spec.containers section

Sample Deployment Yaml with probes:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: Myapp-deployment
  labels:
    apptype: java
spec:
  replicas: 3
  selector:
    matchLabels:
      apptype: java
      tier: web
  template:
    metadata:
      labels:
        apptype: java
        tier: web
    spec:
      containers:
      - name: [container name]
        image: [image from any container registry]
        command: ["/bin/sh"]
        args: ["java -Xmx2g -Xss256k -XX:MaxMetaspaceSize=256m -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/my-heap-dump.hprof -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/var/log/myAppgc.log -jar [application.jar] --spring.config.location=[absolute path of the config maps mounted] "]
        ports: 
        - containerPort: 8080
        volumeMounts:
        - name: appconfig
          mountPath: "/config/application"
          readOnly: true
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 3
          periodSeconds: 3
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 3
          periodSeconds: 3
      volumes:
      - name: appconfig
        configMap:
        name: [configmap-name]

Note: InitialDelaySeconds need to be higher value than application start up time

Here are the few fields we need to consider while configuring probes:

  1. initialDelaySeconds: Number of seconds after probe will start
  2. periodSeconds: gap between probe start
  3. timeoutSeconds: probe time out
  4. successThreshold: number of success probes after failure
  5. failureThreshold: Waiting time to perform restart container(Liveness Probe) and marking container unready(Readiness Probe)
  6. scheme: HTTP or HTTPS Defaults to HTTP.
  7. path: Path to access on the endpoint
  8. port: port to access on the container

Step2:

Save the above mentioned deployment yaml and deploy it in kubernetes cluster by executing the below command

kubectl apply -f [deployment.yaml]
430
Technology
Prev PostConfigure Pod Anti-affinity and Pod Disruption Budget in Kubernetes deployment for High availability
Next PostCreate TCP/UDP Internal Load Balancer (ILB) on Google Cloud Platform (GCP) using managed and unmanaged instance groups
c4i-web
We are on a mission to energize everyone to embrace technology for profitable employment.
Contact Us
Corporate Office
26606 Cook Field Rd Suite 400 Katy TX-77494
713-565-1199
346-447-6884
Hyderabad
Hyderabad
Spacion Business Centre, Level 5, Spacion Towers, HITEC City, Hyderabad, Telangana 500081
+91 836 737 5363
Copyright © 2021. All Rights Reserved.