Sunday, August 25, 2024

Kubernetes Pods - [Part 4]



Copy the files from pods to local worker nodes.

#kubectl cp <pod-name>:/captures/capture3.txt ./capture3.txt

Example:

#kubectl cp kuard:/dev/termination-log ./termination-log

$ ls -ltr termin*

ls: cannot access 'termin*': No such file or directory

$ kubectl cp kuard:/dev/termination-log ./termination-log

tar: removing leading '/' from member names

$ ls -ltr termin*

-rw-r--r-- 1 root root 0 Aug 25 06:55 termination-log

Copy a file from local machine into pod.

#kubectl cp $HOME/config.txt <pod-name>:/config.txt

Example:

$ kubectl cp thiru kuard:/tmp/thiru

$ kubectl exec  kuard ls /tmp/thiru

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.

/tmp/thiru

$

Liveness probe define that per container and ensure that health of the application and pod are fine, normal health check the pod and flag as health even if application is down.

Example:

apiVersion: v1

kind: Pod

metadata:

  name: kuard

spec:

  containers:

    - image: gcr.io/kuar-demo/kuard-amd64:blue

      name: kuard

      livenessProbe:

        httpGet:

          path: /healthy

          port: 8080

        initialDelaySeconds: 5

        timeoutSeconds: 1

        periodSeconds: 10

        failureThreshold: 3

      ports:

        - containerPort: 8080

          name: http

          protocol: TCP

The preceding Pod manifest uses an httpGet probe to perform an HTTP GET request against the /healthy endpoint on port 8080 of the kuard container. The probe sets an initialDelaySeconds of 5, and thus will not be called until 5 seconds after all the containers in the Pod are created. The probe must respond within the 1-second timeout, and the HTTP status code must be equal to or greater than 200 and less than 400 to be considered successful. Kubernetes will call the probe every 10 seconds. If more than three consecutive probes fail, the container will fail and restart.

while failed of liveness check is going to trigger the restart of the pod. There are 3 options for restart policy for the pod.

Always [by default] 

onFailure [ restart only when the liveness is getting failed or non zero process exit code]

Never

Readiness probe:

Liveness probe is determinate if an application is running properly while readiness probe describes when a container is ready to serve user requests. Container that fails readiness checks are removed from service load balancers.

No comments:

Post a Comment