Good morning everyone and welcome back to a new Tooldech article. Today we’ll be talking about Serverless.
Kubernetes (K8s) is a platform open-source that helps you run and manage applications. containerizzate (that is, in containers, like Docker ones) on one or more servers. It automates complex tasks such as to scale the number of istances repair automatically restarting the components that fail and distribute deploying new versions with minimal downtime.
From an architectural point of view, a cluster kubernetes is compose from:
- Control planethe “brain” that makes decisions (scheduling, desired state).
- Nodi (worker)the “arms” that run the containers (your apps).
I’d like to spend a few more words on some of the fundamental concepts when it comes to Kubernetes.
- Podthe smallest unit of execution in Kubernetes. It contains… one or more container that share network and storage. Usually, 1 Pod = 1 instance of your app.
- Nodo (Node)a machine (physical or virtual) where the Pods run. A cluster has one or more nodes
- Deployment: specific how much replicate of your app you want and takes care of creating or recreating them (ensuring the desire state)).
- Serviceprovides a stable network endpoint to reach the Pods (which can be created, terminated, and change their IP). Common types include: ClusterIP, NodePort, LoadBalancer.
What we’ll use for our first local cluster
To learn without spending anything or touching the cloud, we’ll use Minikubea tool that creates a Kubernetes cluster in local. We to star with driver Docker Because is easy and portable.
Existing alternativekind, k3s)but for the very first steps, Minikube remains the most straightforward option.
Prerequisites and Installation (Windows, macOS, Linux)
Recommended Minimum Requirements
- CPU: 2 core
- RAM: ≥ 2 GB (better 4 GB)
- Disk: ≥ 20 GB free
- Connection internet
- Gestore VM/Container: Docker, VirtualBox, ecc. (useremo Docker) minikube
Install kubectl ( the CLI of Kubernet
I recommend installing kubectl and minikube on Linux. I'll leave the macOS and Windows commands in the tutorial, but the tutorial is based on Linux commands! You'll find links to the installation documentation.
brew install kubectl
kubectl version --client
Windows (Chocolatey da PowerShell Admin):
choco install kubernetes-cli -y
kubectl version --client
Linux (download binario ufficiale, esempio x86_64):
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
chmod +x kubectl
kubectl version --client

Install Minikube
The tutorial is based on Linux commands! You'll find links to the installation documentation.
brew install minikube
minikube version
choco install minikube -y
minikube version
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

minikube version

NotaWe'll be using the driver Docker (preferred on Linux/macOS/Windows). The "none" driver is for advanced users; avoid using it for initial testing. Starting the cluster with Minikube
Starting the cluster with Minikube
At this point we start powering up the minikube cluster with a local cluster.
Let's prepare the cluster. I'm doing this test with the user root, For testing purposes, it can still be used for production environments, but it is strongly discouraged. Outside of this test, it would be useful to prepare the permissions for the Docker driver to use minikube:
minikube start --driver=docker --force
minikube status

kubectl cluster-info
kubectl get nodes

The first app on Kubernetes (Nginx)
Let's create a Deployment called hello-k8s starts an nginx:
kubectl create deployment hello-k8s --image=nginx
create deploymentcreates a Deployment object.--image=nginxuse public imagenginx(default port 80).

Let's check the creation.
kubectl get deployments

kubectl get pods -o wide

If all went well you should see 1 pod running.
3-replica ladder:
kubectl scale deployment/hello-k8s --replicas=3
kubectl get pods -o wide

Expose the app to the network (Service NodePort)
To reach Nginx from your PC, we expose the Deployment with a Service type Service NodePort:
kubectl expose deployment/hello-k8s --type=NodePort --port=80 --target-port=80
--type=NodePortOpens a port on the node (default range 30000-32767).--port=80“external” door of the Service.--target-port=80: porta nel container (Nginx)
Check the assigned port number:
kubectl get service hello-k8s

You will see something like 80:30xxx/TCP where 30xxx is the NodePort.
Final Demo
With Minikube, you can directly get the URL reachable by the browser:
minikube service hello-k8s --url

Copy the returned URL (e.g. http://127.0.0.1:xxxxx o http://<IP>:30xxx)and try:
curl -I $(minikube service hello-k8s --url)

You should see an HTTP/1.1 200 OK and Nginx headers. Opening the URL in your browser will bring up the Nginx welcome page (“Welcome to nginx!”).
Cleaning the environment
When you're done, you can remove the resources:
kubectl delete service hello-k8s
kubectl delete deployment hello-k8s
And, if you want to shut down and wipe the local cluster:
minikube stop
minikube delete

Conclusions + Call-to-Action
You’ve created your first local Kubernetes cluster, deployed an Nginx app ,, scaled it , and exposed in to the network
Thanks for reading this far and finding this article interesting, see you in the next tutorial!
👉 Was this guide helpful?
Try our other tutorials on Docker and DevOps.
Follow us on social media:
