Is It Hard to Learn Kubernetes?
There seems to be a lot of debate around whether Kubernetes is difficult to grasp and learn. The honest answer, it all depends on your experience. For example, if you have worked with YAML files while using Ansible, Kubernetes may come easier for you than others. But what if you have absolutely no experience?
Let's take a look at Kubernetes at a high level, break down several of its components, and then discuss how hard they are to learn.
Kubernetes at a High Level
Kubernetes, also known as K8s, is a tool used to orchestrate, scale, and provide services between containerized applications. There's a lot to unpack there, so let's break that down using the three key concepts we just mentioned.
Orchestrate. Kubernetes runs multiple replicas of the same application using pods. For example, you may have five pods with the same containerized application in each of them. K8s will orchestrate these pods by making sure that proper load balancing occurs between each of them, or spins up a new one if a particular pod fails. Like how a maestro conducts an orchestra, Kubernetes conducts containerized applications.
Scale. Kubernetes detects when additional pods need to be created to maintain a desired state of the application. For instance, let's say you own an e-commerce website and suddenly your site crashes on Cyber Monday. If you had Kubernetes, it could have been programmed to ensure available resources were spun up on time.
Provide Services. For Kubernetes to work as intended, it needs to leverage at least one of the four built in services: Cluster IP, Node Port, Load Balance, and External Name. The different services are what connect all the pods in a node, and subsequently all the nodes in a K8s cluster.
So far, understanding the core definition of Kubernetes is only slightly difficult for those brand new to the field. The biggest obstacle is understanding all the jargon that pertains to the technology.
Now that we have reviewed the purpose of Kubernetes, let's discuss the two different ways to deploy a Kuberenetes stack..
Imperative vs. Declarative
An imperative Kubernetes operation uses the kubectl command-line interface, while a declarative operation uses a YAML file. Kubectl is Kubernetes' custom CLI. Kubectl allows you to do everything required to build, customize, and deploy a cluster. Declarative deployments on the other hand are completely written in YAML files. These YAML files can then be uploaded to source control and executed by whomever, whenever desired.
Imperative deployments are great for learning Kubernetes, and experimenting with different workloads. Declarative deployments however are the bread and butter of the technology, and are what is used 99% of the time. With that in mind, let's jump to YAML files.
What are YAML Files
There is no way to discuss the level of difficulty without mentioning YAML files. The core purpose of a YAML file is to provide instructions on how you would like your deployment to be run.
The image above is a typical example of a YAML file. A YAML file is a data-serialization language that works by keys and values. Everything to the left of a colon is a key. Everything to the right of a colon is a value. The key is a property read by the computer, and the output of that particular key will always be the value, thereby allowing you to abstract different requirements for use on multiple nodes.
The more complex the system, the more complex the YAML files will become. To ease yourself into it, don't just look at some massive deployment file and expect to understand it. Instead, review a couple of the main keys and understand what is going on.
For example, in the YAML file above there is a key called kind. Every Kubernetes file will have a "kind" key. The "kind" key represents which type of Kubernetes object is being created. In this instance, we're creating a deployment file. It could have been a service, pod, daemonSet, etc.
Other keys that will generally always be associated with the YAML file are spec, metadata, and api version. (Of course, that is all dependent on the "kind".) To conclude the YAML discussion, learning how to use YAML files is easy and very advantageous; because YAML files aren't just used in Kubernetes — they're used everywhere.
However, learning how to tailor YAML files to create a successful Kubernetes deployment is another beast entirely. If YAML is the glue that holds Kubernetes together, what are the building blocks that are getting glued together? That would be Docker containers.
Kubernetes and Docker
Docker containers are the bedrock technology of Kubernetes. In fact, the entire point of Kubernetes is to monitor, orchestrate, and otherwise maintain them. Learning Docker is instrumental to understanding and utilizing Kubernetes.
Docker is a virtualization technology used to containerize applications. That means a developer can bundle an application's code and other dependencies so that they may be shipped to other machines.
Say you are a developer working on a team that is creating a new website. You are working on the frontend, using Angular while your colleague is writing the backend in Python. You notice a bug whenever you are trying to pull data down from the database. Unfortunately, your colleague is a thousand miles away because your team is global. How do you easily show him the error without needing to replicate your entire environment?
It's easy, send him a Docker container! As long as he has Docker too, he will be able to unpack your container, hit the end point, and notice the bug.
Now that we've looked at a basic example, say you want to run multiple copies of the exact same app. Perhaps you want to load balance a website to curb latency. A containerized app would be great for that, because it is completely hardware agnostic. In fact, it would be great if there was a way to automate these sets of containers so that when one goes down, an exact replica is spun back up. This example is exactly what Kubernetes does, and that is how containers are fundamentally related to Kubernetes.
So to answer the question, is Kubernetes hard? Yes, it is fairly difficult to understand, and even harder to implement. However the journey of a 1,000 miles starts with a single step, and CBT Nuggets provides plenty of help along the way.
Again, it's imperative to understand Docker. Get to know the Docker CLI, how to compose a docker container, and then executing one. Understand how to create multiple Docker containers using Kubernetes. Do this from both kubectl and by writing a YAML file.