DevOps Classroomnotes 03/Dec/2022

Kubernetes Networking Model

  • Refer Here to understand the internals of kubernetes networking
  • K8s dictates following
    • all Pods can communicate with all other Pods without using network address translation (NAT).
    • all Nodes can communicate with all Pods without NAT.
    • the IP that a Pod sees itself as is the same IP that others see it as.
  • All the Pods in the k8s cluster have a CIDR Range
  • To implement these k8s takes linux kernel networking features such as netfilter and iptables.

Kubernetes Pods

  • K8s Pods are atomic unit in k8s cluster.
  • Pods have containers which run applications
  • Consider the wordpress example. We need to have wordpress container and mysql container for wordpress to work
  • To run this with Pods
    Preview
  • Now lets understand scaling.
    Preview
  • Pod life cycle Refer Here
  • Pod Phases Refer Here
  • Pod restart policy: Always, Never, OnFailure
  • Lets write a spec which sleeps for 2 seconds (sleep 2)

    • restart policy Never
    • not specify restart policy in spec
  • Refer Here for the specs
    Preview
    Preview
  • Pods can run 3 types of containers

    • Containers => Where we run our applications
    • init containers:
      • These containers are created one by one and only after its completion, the normal containers are created.
      • We will use these containers for any initial setup or configuration kind of purposes
    • ephemeral containers:
      • No guarantee containers, they are used rarely in the case of debugging or trouble shooting containers in Pod
  • Lets create a Pod with 2 init container which sleep for 5 seconds and then in container we run nginx.
  • Refer Here for the manifest written
  • Now create the pod
    Preview
  • Writing YAML files to describe the status is referred as declarative approach, k8s also supports imperative approach
kubectl run nginx --image=nginx --restart=Never

Preview
* Refer Here for some example imperative commands

Replication Controller

  • Refer Here for official docs
  • There are many cases where we would want to run multiple instance of a application.
  • In k8s we run application in Pod and to set mutlple instances we use replica sets or replication controllers.
  • Lets try to run 5 nginx Pods in our cluster
  • Refer Here for the manifest
    Preview
  • We got an error with selector
  • To resolve this error we need to understand the concept of labels in k8s.
  • Refer Here for manifest with labels defined and selectors
    Preview
  • Refer Here for the fix with matchLabels section removed
  • NOte: We will work on this tommorow

Labels in K8s

  • Refer Here
  • In k8s as part of metadata we can apply labels to the resources.
  • These labels help in querying resources based on conditions according labels defined
    Preview
  • Lets create 2 pod specs with label specifications as shown above
  • Refer Here for the changes
    Preview
    Preview
  • Lets run some command line selectors
    Preview
    Preview

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube