Here, we'll quickly go over two ways to set up Kubernetes:
We'll start with the first option.
kubectl is the universal entry point for controlling all types of Kubernetes clusters. It's a command-line client that communicates with the API of a cluster over REST.
We'll explore kubectl gradually throughout the TPs. However, note that:
The installation method doesn't matter much. To install kubectl on Ubuntu, we'll simply do: `sudo snap install kubectl –classic`.
Minikube is the most popular development version of Kubernetes (locally). It's maintained by the Cloud Native Foundation and very close to upstream Kubernetes. It allows simulating one or more cluster nodes in the form of Docker containers or virtual machines.
We will typically use Docker as the runtime for minikube (the k8s nodes will be containers simulating servers). This is, of course, a development configuration. However, it behaves very similarly to a real cluster.
Minikube automatically configures kubectl (in the `~/.kube/config` file) so that we can connect to the development cluster.
Display the kubectl version again. This time the version of Kubernetes running on the active cluster is also displayed. Ideally, the client and the cluster should be in the same minor version, for example, 1.20.x.
To allow kubectl to complete command and resource names with <Tab>, it's useful to install Bash autocompletion:
sudo apt install bash-completion source <(kubectl completion bash) echo "source <(kubectl completion bash)" >> ${HOME}/.bashrc
Now you can press <Tab> to complete your kubectl commands, which is very useful!
It seems that there is only one resource in our cluster. This is the Kubernetes API service, so that we can communicate with the cluster.
In reality, there are usually others hidden in other namespaces. In fact, the internal elements of Kubernetes themselves run as Kubernetes services and daemons. Namespaces are groups that serve to logically isolate resources and in terms of rights (with Kubernetes' Role-Based Access Control (RBAC)).
To verify this we can:
A Kubernetes cluster typically has a namespace called `default` in which commands are run and resources created if nothing is specified. It also has a namespace `kube-system` where k8s system processes and resources reside. To specify the namespace, we can add the `-n` argument to most k8s commands.
We will now deploy a first containerized application. Deployment is more complex than with Docker (and Swarm), especially because it's separated into several objects and more configurable.
This command creates a deployment object. We can study this deployment with the `kubectl describe deployment/microbot` command.
At this stage, the deployment is not yet accessible from outside the cluster, so we need to expose it as a service:
A service allows exposing a deployment either by port or using a load balancer.
To expose this application on the port of our choice, we should use a LoadBalancer.
We won't see it here (we would need to use the Minikube MetalLB addon).
But we can still run a command in our dev environment: `kubectl port-forward svc/microbot-service 8080:8080 –address 0.0.0.0`
You can now access your app via: [http://localhost:8080](http://localhost:8080) Minikube also integrates a way to access our service: it's the `minikube service microbot-service` command.
Can you explain what the app does?
To save time in Kubernetes commands, we generally define an alias: `alias kc='kubectl'` (to be put in your .bash_profile by doing `echo “alias kc='kubectl'” » ~/.bash_profile`, then `source ~/.bash_profile`). You can then replace `kubectl` with `kc` in the commands. Also, to save time on the command line, most Kubernetes keywords can be abbreviated: - `services` becomes `svc` - `deployments` becomes `deploy` - etc. The complete list: [https://blog.heptio.com/k
ubectl-resource-short-names-heptioprotip-c8eff9fb7202](https://blog.heptio.com/kubectl-resource-short-names-heptioprotip-c8eff9fb7202)
Try displaying the service accounts (users) and namespaces with a short command.
Lens is a nice graphical interface for Kubernetes. It connects using the default `~/.kube/config` configuration and will allow us to access a much nicer dashboard. You can install it by running these commands:
sudo apt-get update; sudo apt-get install -y libxss-dev curl -fSL https://github.com/lensapp/lens/releases/download/v4.0.6/Lens-4.0.6.AppImage -o ~/Lens.AppImage chmod +x ~/Lens.AppImage ~/Lens.AppImage &
Setting up a K8s cluster in the cloud with a provider like DigitalOcean or Scaleway
This file contains the kubectl configuration suitable for connecting to our cluster.
Merge the kubectl configuration