Appearance
Kubernetes

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
Installation
Docker for Mac
Recently Kubernetes has been included directly on the Docker app, you can activate Kubernetes on Preferences → Kubernetes → Enable Kubernetes:

Brew
bash
brew install kubernetes-cliUseful commands
A Cheat Sheet can be found on the official website for more detailed information.
Cluster info
bash
kubectl cluster-infoContext
bash
kubectl config get-contexts
kubectl config set-context <context>Namespace
bash
kubectl config set-context --current --namespace=<namespace>Proxy
We can have a connection between our host and the Kubernetes cluster.
bash
kubectl proxy
curl http://localhost:8001/versionNodes
bash
kubectl get nodesDeployments
Deploy containerized applications.
Create update instances of your application.
Once the application instances are created, a Kubernetes Deployment Controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster.
bash
kubectl create deployment kuberenetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1bash
kubectl get deploymentsPods
Kubernetes abstraction that represents a group of one or more application containers (ex Docker) and shared resources for those containers. The resources include:
- Shared storage, as Volumes
- Networking, as unique cluster IP address
- Information about how to run each container, such as the container image verison or specific ports ot use
A Pod always run on a Node.
Pods information
bash
kubectl get pods
kubectl describe podsPod name
bash
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAMEbash
curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/Logs
bash
kubectl logs $POD_NAMEExecute command
bash
kubectl exec $POD_NAME env
kubectl exec -ti $POD_NAME bashServices
Required to access to a deployment.
Services match a set of Pods using labels and selectors, a grouping primitive that allows logical operation on objects in Kubernetes.
bash
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
# NGINX example with LoadBalancer
kubectl expose deployment nginx --port=80 --type=LoadBalancerbash
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORTbash
curl $(minikube ip):$NODE_PORTbash
kubectl describe deploymentLabels
bash
kubectl get pods -l run=kuberenetes-bootcampbash
kubectl get services -l run=kuberenetes-bootcampbash
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAMEbash
kubectl get pods -l run=kuberenetes-bootcampbash
kubectl get pods -l run=kuberenetes-bootcampbash
kubectl get pods -l run=kuberenetes-bootcampApply label
bash
kubectl label pod $POD_NAME app=v1
kubectl describe pods $POD_NAME
kubectl get pods -l app=v1Delete
bash
kubectl delete service -l run=kubernetes-bootcamp
kubectl get servicesScaling
bash
kubectl get deploymentsbash
kubectl scale deployments/kubernetes-bootcamp --replicas=4
kubectl get deploymentsbash
kubectl get pods -o wide
kubectl describe deployments/kubernetes-bootcampLoad balancing
bash
kubectl describe services/kubernetes-bootcampbash
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORTbash
curl $(minikube ip):$NODE_PORTRolling update
Update image
bash
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
# Check status
kubectl rollout status deployments/kubernetes-bootcampRollback update
bash
kubectl rollout undo deployments/kubernetes-bootcampkubectl
bash
kubectl get - list resources
kubectl describe - show detailed information about a resource
kubectl logs - print the logs from a container in a pod
kubectl exec - execute a command on a container in a podDelete all
bash
kubectl delete all --all