Kubernetes¶
List of interesting links:¶
- Kubernetes official webpage:
- Kubernetes documentation:
- Kubernetes basic tutorial:
- Minikube git page:
- Minikube tutorial:
https://kubernetes.io/docs/setup/learning-environment/minikube/
- Kubectl cheatsheet:
An easy way to understand kubernetes is following the tutorial “kubernetes-basics” https://kubernetes.io/docs/tutorials/kubernetes-basics/ that provides an interactive console to tests the commands of the tutorial. However it is also interesting to have installed a minikube in your local machine or in a virtual machine to increase the experience
Keys to learn¶
Deployment¶
A Deployment controller provides declarative updates for Pods and ReplicaSets. Learn more about deployments
Create a deployment
kubectl run <myDeployment> --image=<myImage>:<version> --port=8080
Check current deployments
kubectl get deployments
Create a proxy. The ports will be accessibles from outside the pod
kubectl proxy
Access to the pod proxy
curl http://localhost:8001/api/v1/namespaces/default/pods/<pod name>/proxy/
Pods¶
A Pod is the basic execution unit of a Kubernetes application. Learn more about pods
Get pods information
kubectl get pods
kubectl describe pods
kubectl get pods -o wide
Get pod log
kubectl logs <pod name>
Execute command inside the pod
kubectl exec <pod name> <command>
NOTE: The name of the container can be omitted if there is only one container.
Open a bash session
kubectl exec -ti <pod name> bash
Services¶
An abstract way to expose an application running on a set of Pods as a network service. There are different kinds of services. Learn more about services
Get services
kubectl get services
kubectl describe services
Create a new service (expose it as nodeport)
kubectl expose deployment/<myDeployment> --type="NodePort" --port 8080
Get info from a service
kubectl describe service/<myDeployment>
Connect to the port (via cluster ip)
curl $(minikube ip):<node port>
Delete a service $ kubectl delete service -l run=<my deployment>
Labels¶
Labels are key/value pairs that are attached to objects, such as pods. The labels group the different objects (pods, services, deployments, …) helping to select one or a set of them when a command is applied. Learn more about Labels
Using labels
kubectl get pods -l run=<my deployment>
kubectl get services -l run=<my deployment>
Add labels
kubectl label pod <pod name> app=v1
Scaling the application¶
Scaling helps to add more replicas of a pod, for instance in case when traffic increases. Learn more about scaling
Scale (or downscale)
kubectl scale deployments/<my deployment> --replicas=4
See the status
kubectl get deployments
kubectl describe deployments/<my deployment>
See the loadbalancer in the default service
kubectl describe services/<my deployment>
Updating the image¶
Kubernetes allows to update an Pod image without interrupting the service. And rollback the operation if something is wrong. Learn more about updating images
To change the image
kubectl set image deployments/<myDeployment> <myContainer>=<myImage>:<version>
To check the current status. this message will be appears when finish and all is right “deployment <my Deployment> successfully rolled out”
kubectl rollout status deployments/<myDeployment>
To see the current version in each pod && to see errors
kubectl describe pods
Undo an update
kubectl rollout undo deployments/<myDeployment>
Minikube playground¶
Minikube allows to run kubernetes in a local environment. https://github.com/kubernetes/minikube
To run minikube is simple
minikube start
Minikube requires VirtualBox (by default) or KVM (the recommended in Linux) installed. To use minikube with KVM can be used instead with the flag –vm-driver
minikube start --vm-driver kvm2