Essential Kubernetes that you should know
It doesn't matter if you are not responsible for deploying your applications to servers; you must understand how your code is deployed to write better, resilient code. Today there are numerous ways by which an application is deployed onto a development/production server. Having said that, containerization is by far the most common way. Now I won't reiterate why it is so prominent, but here's a brief article you can refer to for its salient features.
Hopefully, you have some background in docker/containers. If not, please do so!
Ok! Now, what's Kubernetes?
Kubernetes is a container orchestration system.
Containers are good! They take minutes to spin up and are ready to serve you those pictures of cats and dogs that you are craving. However, you still need to maintain them manually.
What if a container goes down? Or there is a sudden influx of traffic!
This is where Kubernetes steps in. There are alternatives too - like Docker Swarm and Nomad. But Kubernetes is the de-facto orchestrator.
A Non-exhaustive list of Kubernetes features:
- Automated Scheduling
- Self-Healing Capabilities
- Automated rollouts & rollback
- Horizontal Scaling & Load Balancing
- Offers environment consistency for development, testing, and production
- Infrastructure is loosely coupled to each component can act as a separate unit
- Provides a higher density of resource utilization
- Offers enterprise-ready features
- Application-centric management
- Auto-scalable infrastructure
- You can create predictable infrastructure
Let's briefly discuss some of the concepts which should make you capable enough to deploy small-scale applications.
Level 0 - Absolute basic terms
Cluster
As the name suggests, a cluster is a collection of servers, aka nodes. A cluster could have as many nodes as you want. In the lamest of sense, a cluster can be considered a huge server that aggregates nodes' ram, CPU, disk, and devices into a usable pool.
Master
The master is a collection of components that makes up the control plane of Kubernetes. These components are used for all cluster decisions. It includes both scheduling and responding to cluster events. If you are not running your cluster in a multi-master configuration, your cluster can go down if your master crashed!
Node
It is a single host which is capable of running on a physical or virtual machine. A node runs both kube-proxy and kubelet, which are considered part of the cluster. A node could be a master node or a worker node. Multiple pods can run on a single Node.
Namespace
It is a logical cluster or environment. It is a widely used method which is used for scoping access or dividing a cluster. You can divide the cluster among your projects using namespaces.
Level 1 - Kubernetes Components
Deployments
Deployments are where you define the containers for your applications. Think of them as managers responsible for managing your application pods. They are responsible for maintaining your pod count, replica sets, etc. You can pass environment variables required by your application, define health checks, etc., all in your deployment manifest files.
Pods
Pods are the smallest independent running executable units. It is a group of one or more containers with shared resources. A single node can run multiple deployments, and a single deployment can have multiple pods. Pods are ephemeral in nature, i.e., they lose their state/data on destruction. Hence all persistable data is stored on external "Persistent Volumes."
Services
Ingress
An ingress is an object which controls external access to cluster resources. In many ways, it is analogous to a Load Balancer. Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.
Config Maps
A Config Map is used to store non-confidential data for your applications, such as environment variables. They provide a centralized location to manage your application configurations. Here's how you can access these in your manifest files.
env:
# Define the environment variable
- name: PLAYER_INITIAL_LIVES
valueFrom:
configMapKeyRef:
name: game-demo # your configmap
key: player_initial_lives # The key to fetch.
- name: UI_PROPERTIES_FILE_NAME
valueFrom:
configMapKeyRef:
name: game-demo
key: ui_properties_file_name
Secrets
As the name suggests, Secret objects are used to store confidential configurations such as passwords of databases, API keys, OAuth tokens, ssh keys, etc. Similar to config Maps, they too can be accessed inside Deployments.
All secrets are stored as Base64 encoded values
Level 2 - Kubernetes Configuration YAMLs
Configurations are written in YAMLs/YMLs (Yet Another Markup Language) and allow us to develop our infrastructure as code.
Kubernetes provides us with a comprehensive suite of keys and definitions for our infrastructure needs. To apply this to our cluster, execute
kubectl apply -f <yaml filename>Visit the following links to check out the most prominent Kubernetes resources.
Conclusion
I understand if you feel a bit confused. It's hard to cover such a vast topic in this small of a post. However, this post merely skims the surface, giving you enough Kubernetes knowledge to make conversations and write code keeping the deployment process in mind. And if you want to understand in-depth, you can visit the official documentation or check out my other Kubernetes-related posts.
Until then, Goodbye!