Giter Site home page Giter Site logo

k8s's Introduction

Pods

Manually create a pod from command line

kubectl run my-nginx --image=nginx:alpine

This command will create a pod in cluster under default namespace with nginx docker image. we can get details of the pod by

kubectl get pods

kubectl describe pod my-nginx

However at this point we are not able to reach our pod from external world, so we need to expose it first by

kubectl port-forward my-nginx 8080:80

We can remove this pod by

kubectl delete pod my-nginx

use yml file to describe a pod

the file is nginx.pod.yml

a complete details of the pod can be retrieved by

kubectl get pod my-nginx -o yaml

To get into the pod in shell

kubectl exec my-nginx -it sh

to delete the pod we can use

kubectl delete pod -f nginx.pod.yml

Probes

Liveness Probe

Used to determine if the pod is healthy and running as expected

Example

spec:
    containers:
        - name: my-nginx
          image: nginx:alpine
          livenessProbe:
            httpGet: # a http get type of check on /index.html and on port 80 and expects success or failure or Unknown as result
                path: /index.html
                port: 80
            initialDelaySeconds: 15 # wait for 15 seconds before starting to check
            timeoutSeconds: 2 # timeout of checking is 2 seconds, default 1
            periodSeconds: 5 # check every 5 seconds, default 10
            failureThreshold: 1 # allow 1 failure before taking down the pod, default 3

Readiness Probe

Used to determine if the pod is ready to receive request

Example

spec:
    containers:
        - name: my-nginx
          image: nginx:alpine
          readinessProbe:
            httpGet: # a http get type of check on /index.html and on port 80 and expects success or failure or Unknown as result
                path: /index.html
                port: 80
            initialDelaySeconds: 3 # wait for 3 seconds before starting to check
            periodSeconds: 5 # check every 5 seconds until its up and running
            failureThreshold: 1

Try out the probes

Copy the nginx.pod.yml file and name as nginx.pod.probes.yml and add the readiness and liveness probes

kubectl apply -f nginx.pod.probes.yml

Now sh into the shell of the pod and delete the index.html file

kubectl exec my-nginx -it sh

cd /usr/share/nginx/html

ls

rm index.html

running above commands will terminate the pod and this the terminal will exit as well. If you describe the pod and look for message section, you can see the liveness probe fail message.

k8s's People

Contributors

inianantony avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.