Nerdsense

Kubernetes: 86 the Prime Rib

Greg Heffner August 4, 2024
Load Balancing

When a docker image starts it is expected to work until someone turns it off. BUT... What if the docker image runs out of resources? What if the docker image is over-utilized by traffic? What if the docker host crashes? These are all real questions that have to be thought through when hosting a dockerized application.

Kubernetes or K8s comes from the Greek word for helmsman or pilot. K8s name is derived from the 8 letters between the K and the S. This website you are on right now lives in a K8s cluster. Check out my write-up I have in github about how I built it k8-nginx-webpage.

My first job I had as a teen was in a kitchen. There was a schedule posted at work in the same place every week letting everyone know where to go and when to show up. If someone needed to be off work, needed to leave early, wanted to switch roles, they huddled around the schedule and worked it out and wrote it down for everyone to see the changes. Sometimes schedule changes had to be approved. When I worked there, I was the best fry guy these old guys ever seen in their life, so that meant I never got to do the fun jobs. They needed my skills too much on them Combo Apps. ¯\_(ツ)_/¯ All kidding aside there had to be a schedule to be successful. We needed to have the correct amount of people and resources to be able to handle the rush otherwise they would go somewhere else.

When a ticket is printed the expo calls out what is needed from all the stations for the order. For example, if there was a order for two guests, one salad order and one well done steak order, those orders would take two way different times to prepare and two different routes to be plated. The expo person needs to know who gets the salad order and who gets the grill order to make sure the orders go to the correct place. You may need more than one employee working a station though if you expect a lot of work that shift, it would be set-up in the schedule though.

How does it work

K8s schedules the deployment and its pods the same way a restaurant schedules its employees for the kitchen. In this blogs example there is a 3 node K8s cluster consisting of one primary and two worker nodes for high availability and redundancy.

The primary or scheduler node contains all the details of a deployment. Its jobs is to be the point of reference. Think of the primary node as the expo person in the kitchen. The primary node knows the number of pods or docker images needed, the amount of nodes needed to host the pods, and the ingress and egress traffic routing settings for the deployment. The worker nodes do not need this. They have just what they need to be connected in a cluster and they know who the primary node is and how to get information. All other resources from the worker nodes are applied to an available pool for use with the remaining resources from the primary node. Think of nodes as the different kitchen stations in a restaurant. These stations are responsible for types of services, grill, saute, salad, fry. Once everything is connected together a complete service can be provided. Soup to nuts.

On each node are pods. Think of these pods like baskets containing docker images. Pods can be moved from node to node based either on predefined schedules or resource limits. Think of pods as the employees in the kitchen. There might be one pod that does all the work or multiple pods to split the work. The number of pods needed depends on the schedule and the resources available in the deployment. Just like a restaurant might have a employee thats better working day shift over night shift.

nodes&pods
Kubernetes Node and Pods from GeeksforGeeks

What are the benefits

Redundancy- Normally if a host running a docker image fails or is unavailable, that docker image running becomes unavailable until the host becomes available again. Setting up a deployment in a K8s cluster allows a node become unavailable and pods will be automatically spun up on other nodes restoring services without any intervention. Once the node becomes available again and if a pod needs to move then they can move to that node again.

High Availability- Imagine an influx of traffic that one docker image cant handle. All the traffic past a certain point will be lost as resource unavailable or not found. K8s and its horizontal pod auto-scaler service, can be set with thresholds on the amount of CPU or memory used before a new pod is spun up to support the load. On. Its. Own. Having the ability to automatically add or remove resources based on use is very powerful.

Security- Setting up pod security standards and network policies allows an application to live in a isolated environment from its host server and sets up encrypted pod to pod traffic between devices. Using cloudflared tunnels in addition to the k8s security standards drastically improves application security as well without having to open up firewall ports. Check out cloudflared tunnels and how to route traffic for more info. For more info on k8s security, check out Kubernetes security mechanisms by kubernetes.


Why you should use it

Wrapping all this up I highly recommend someone getting to know K8s. Even if it is just to learn how it works or to figure out how loadbalance your blog. There are so many resources out there to help you learn and understand K8s.

Some great examples of K8s in action are:


There are some very interesting tools that can be used to maintain your clusters and in my case, a website. I have used these tools or still use these tools today for my cluster.

LensImg
Lens is great to have pulled up in the background or to watch when patching. Check out this script I use k8-patchNbounce
K9s img
K9s is great for logging or looking for 403 reasons. I like anything pod level to use K9s.
Locusts img
I use Locust for open source site testing. I use it to trigger CPU, memory, and user loads to test autoscaling.
trivy img
Trivy is great for vulnerability scanning. Ive never been an A student until now haha. Easy when trivy prints vulns and how to fix them

Bing AI explanation

Let’s step into the bustling kitchen of a fancy restaurant, where technology and teamwork blend like the finest ingredients. 🍽️👨‍🍳

Kubernetes (Head Chef): Meet Chef Kube, the head chef! Chef Kube wears a tall hat (like a crown) and orchestrates the entire kitchen. Chef Kube knows every recipe, dietary preference, and allergy alert. When an order comes in, Chef Kube assigns tasks to sous-chefs (nodes) and ensures everything runs smoothly. 🧑‍🍳

Nodes (Sous-Chefs): Sous-chefs (nodes) are the backbone of the kitchen. They handle specific tasks—grilling, chopping, plating. Each sous-chef has their own cutting board (node) and knife (resources). Chef Kube ensures they collaborate seamlessly. 👩‍🍳🔪

Clusters (Kitchen Stations): The kitchen is divided into stations (clusters). Each station has a specialty: grill, sauté, pastry, and more. Just like clusters, these stations work together to create a delightful dining experience. Some stations are physical (real stovetops), while others are virtual (oven simulations). 🔥

Pods (Prep Teams): Imagine a team of sous-chefs working on a single dish. That’s a pod! They gather around, discussing flavors, adjusting spices, and plating garnishes. Each pod focuses on one dish, making sure it’s perfect. 🌿🍽️

Containers (Dish Trays): Imagine the kitchen as a massive workstation. Each dish is like a container. It’s a perfectly plated masterpiece—maybe a creamy risotto, a sizzling steak, or a vegan curry. These dishes (containers) are neatly arranged on trays, ready to be served. 🍲


In summary:
Containers are beautifully plated dishes. Kubernetes is Chef Kube, orchestrating the kitchen. Clusters are specialized kitchen stations. Nodes are sous-chefs with their own cutting boards. Pods are prep teams creating culinary magic. Bon appétit, my little food explorer! 🌟🍴

About Me

I served in the U.S. Army, specializing in Network Switching Systems and was attached to a Patriot Missile System Battalion. After my deployment and Honorable discharge, I went to college in Jacksonville, FL for Computer Science. I have two beautiful and very intelligent daughters. I have more than 20 years professional IT experience. This page is made to learn and have fun. If its messed up, let me know. Im still learning :)

Weather Loop