My FIRST ADVICE is before beginning the study of k8s: you should study in-depth about any application container engine, I suggest docker but there are many others like rkt, runc or any other that follows OCI specifications.
If you feel comfortable in Docker, keep going, in any other situation you will need to get some skills, it can be done by yourself. As a developer it won't be too complicated:
- the documentation site can guide you with several examples and practical tasks.
- docker free lab is very useful too, easy and intuitive and mainly it encompasses the whole learning process in Docker.
ONCE that we know at least the most important aspects related with container engine let’s start.
At this point should be obvious for everyone concepts like Cluster or Node
So first things to know:
- What k8s really is? It is an open source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployment, maintenance and scaling of applications.
- The components of k8s
The previous pictures show us the basic infrastructure BUT where are the containers?. Our target is to deploy and finally run applications that are living in our containers. Our containers are living into the k8s PODs. These PODs are the basic building block in k8s and the most important aspects in this process are our applications hosted in our containers and living in those PODs at the same time.
Because our target is to deploy and finally run applications this is the whole picture that we have at this point:
A Cluster: that contains NODEs [1 Master - 1.. n Worker]
Worker Nodes: Contain : PODs
PODs: Contain: Containers
Containers: It contains applications with their own environments.
In the previous picture there are some elements that I haven't mentioned yet (volume), I will talk about it in next posts but you can get the idea that the POD's volume is similar at docker container volume in Docker.
These PODs are living in NODEs, but which NODEs? Who decides which node spin up an specific POD?
If we take a look at the Master Node components we can see kube-scheduler, it is responsible for creating a POD in a specific node. The kube-scheduler watches newly created PODs that have no node assigned, and selects a node for them to run on, this process is not so simple, many factors taken into account for scheduling decisions include individual and collective resource requirements. In next posts we'll see that scheduler behavior can be changed and how some times you can choose in what node your POD can spin up.
There are several way for POD creations BUT all of them involve a reference to images running on containers.
From the developer’s point of view is too easy understand k8s PODs creations process, it has two main components:
- controller
- custom resource definition
and third aspect is how can we talk to the cluster, k8s lets to do that by different ways:
- command line interface (kubectl) that will be running commands against K8s clusters.
- execute kubectl as a reverse proxy: kubectl proxy --port=8080 & and then call the k8s REST api
- programmatic access can be implemented in different ways
So it is up to you, if your are familiar with RESTful environment you can access through the k8s REST API. The API is documented through Swagger so you will have an interface or apply a curl with the proper command.
In this case I am going to use the command line interface (kubectl) that will be running commands against Kubernetes cluster.
kubectl syntax: kubectl [command] [TYPE] [NAME] [flags]
kubectl + creations commands + definition document
Every time that the above statement take place the object defined in our definition document must be validated by kube-apiserver before configure data to any api objects(pods, services, replicationcontrollers, and others)
creations commands(to create api objects):
definition document: a custom resource definition[yaml or json document] that should describe a Controller used during the creation process. In our case our target is the POD creation.
In k8s, a Controller is a control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state in this case we are talking about our desired state, it will be a POD.
Let's see some definition document examples and its relations with the creation commands
Let's see some definition document examples and its relations with the creation commands
# nginx-deployment.yaml document describe a desired state in a Deployment object, and the Deployment controller changes the actual state to the desired state at a controlled rate. create -f https://raw.githubusercontent.com/ldipotetjob/k8straining/develop/yamldefinitions/nginx-deployment.yaml # nginx-repcontroller.yaml describe a ReplicationController object create -f https://raw.githubusercontent.com/ldipotetjob/k8straining/develop/yamldefinitions/nginx-repcontroller.yaml
Some yaml definitions documents examples
Every thing done here is from a software developer perspective so in the same way when we are going to implement our project:
- Local projects/environments: means create/run everything in local.
- Production projects/environments: means upload to cloud environment created by ourselves or by a certified provider.
- the online training platforms[katacoda], some time run too slow but if fine just for test.
- install a local environment, it is very easy with minikube. It is a configurable environment that let you a simulation of a k8s cluster.
- install k8s in your bare metal/laptop.
- whole references of kubectl command line [you can find here examples about how to use a kubectl command with its flags and arguments]
- kubectl Cheat Sheet
Is very important to know that as a developer docker & kubernetes must be familiar for us. Do not try to memorize commands or sintaxis. Try to understand how the whole system works, the idea. Dive in K8s documentation in an ordered way. The following topics are a very good starting point:
The aforementioned aspects are physical and logical objects, to enable that every thing can work together I will need some abstract aspects for example services. In next posts I am going to review in-depth k8s services and its relationship with the rest of k8s elements.
- Kubernetes architecture
- Containers
- Workloads(Pods and Controllers)
The aforementioned aspects are physical and logical objects, to enable that every thing can work together I will need some abstract aspects for example services. In next posts I am going to review in-depth k8s services and its relationship with the rest of k8s elements.