DevOps Classroomnotes 09/Sep/2023

Pods Contd

  • Scaling: Scaling in k8s means increasing number of Pods not containers in Pod. For Scaling pods we would learn Replica set/Replication Controller etcs..

How k8s identifies objects: Labels

  • Label is a key pair examples are
    • app: nginx
    • version: v1.0
  • Labels are used to select/query kubernetes objects
  • Refer Here for official docs on labels
  • Selectors in k8s help in querying objects using labels
  • selectors are of two types
    • Equality Based Selectors
    • Set based selectors

Pod with Labels

  • Overview:
  • Refer Here for the changes done
  • Create pods

Pod with container with additional commands

  • I have to add a container to the pod in addition to nginx which has a docker command docker container run -d alpine sleep 1d
  • Refer Here for the changes

Interacting with containers

  • In docker docker container exec -it or docker container exec
  • In k8s we have kubectl exec
  • Interactive tty

What happens when container goes into exited state

  • Lets create a pod with alpine container which exits
  • Refer Here for the changes
  • kubernetes tries to restart containers, if it fails continuous k8s keeps trying and gives the status as CrashLoopBackoff
  • Kuberentes restarts the containers always as the restartPolicy Default value is Always, which we can change Refer Here

Container types in Pod

  • init containers: These containers are created prior to actual/main containers. ideally these containers should be short lived and majorly for meeting preconditions to run your application. Refer Here for official docs
  • containers: This is where we run actual applications and they are expected to be living forever (continously)


Pod Lifecycle

Activity (in docker)

  • Create a nginx container with 128 MB of RAM
  • Create a jenkins continer with “0.5” cpu and 256 MB of RAM
docker container run  -P -d  --memory 128m nginx
docker container run --name r-memcpu-jenkins -P -d --cpus="0.5" --memory 256m jenkins/jenkins
docker stats

Resource Restrictions in Pods

  • Refer Here for official docs
  • Limits in Resoruce Restrictions mean maximum size that will be allocated (upper bounds/limits) and request are lower limits
  • Exercise: Write the manifest to run above mentioned docker containers in Pod

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner