Sujeet Padhi
Sujeet Padhi

Reputation: 264

Kubernetes - What happens if startupProbe runs beyond periodSeconds

I have a Deployment which runs a simple apache server. I want to execute some commands after the service is up. I am not quite sure how much time the post action commands going to take. I have "timeoutSeconds" set as more than "periodSeconds".

Kubernets Version: 1.25

apiVersion: apps/v1
kind: Deployment
metadata:
  name: readiness
spec:
  replicas: 1
  selector:
    matchLabels:
      app: readiness
  template:
    metadata:
      labels:
        app: readiness
    spec:
      containers:
        - image: sujeetkp/readiness:3.0
          name: readiness
          resources:
            limits:
              memory: "500M"
              cpu: "1"
          readinessProbe:
            httpGet:
              path: /health_monitor
              port: 80
            initialDelaySeconds: 20
            timeoutSeconds: 10
            failureThreshold: 20
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /health_monitor
              port: 80
            initialDelaySeconds: 60
            timeoutSeconds: 10
            failureThreshold: 20
            periodSeconds: 10
          startupProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - |-                 
                  OUTPUT=$(curl -s -o /dev/null -w %{http_code} http://localhost:80/health_monitor)
                  if [ $? -eq 0 ] && [ $OUTPUT -ge 200 ] && [ $OUTPUT -lt 400 ]
                  then 
                    echo "Success" >> /tmp/post_action_track
                    if [ ! -f /tmp/post_action_success ]
                    then
                      # Trigger Post Action
                      sleep 60
                      echo "Success" >> /tmp/post_action_success
                    fi
                  else 
                    exit 1
                  fi
            initialDelaySeconds: 20
            timeoutSeconds: 80
            failureThreshold: 20
            periodSeconds: 10

When I run this code, I see very strange results. As "periodSeconds" is 10 and my script has a sleep of 60 seconds, should not the start up probe trigger atleast 6 times, but it only triggers 2 times. I am checking the contents of files /tmp/post_action_success and /tmp/post_action_track to identify how many times the probe triggers. (Count the number of success inside the files)

Question: If the previous instance of startup probe is running, then is the startupProbe triggered on top of it or not ? If yes, then why it triggered only twice in my case.

Another observation: When I set below options

initialDelaySeconds: 20
timeoutSeconds: 5
failureThreshold: 20
periodSeconds: 10

Then the content of file /tmp/post_action_success shows sleep/timeoutSeconds (60/5)=12 "success". Can someone please explain how this works.

Upvotes: 0

Views: 573

Answers (1)

adelmoradian
adelmoradian

Reputation: 476

I think the reason you see the probe being triggered twice is because of timeoutSeconds: 80. See this question. Also the official doc is quiet handy in explaining the other fields.

Perhaps you can set initialDelaySeconds: 61 instead of using sleep in you script?

Upvotes: 1

Related Questions