Clone https://github.com/betabandido/minikube-provisioner and follow the instructions there to setup a Kubernetes cluster using minikube.
You might want to use tmux
to have multiple virtual terminals multiplexed into a single real one. Ctrl+B C
creates a new window. Ctrl+B <number>
switches to the specified window (using its index). Ctrl+B [
enters scroll mode, and q
goes back to normal mode.
sudo minikube addons enable heapster
sudo minikube addons enable metrics-server
Run the following command to list all the different resources in the cluster:
kubectl get all --all-namespaces
cd ~/k8s-workshop/hello
sudo docker build -t hello:0.1 .
Deploy the application on Kubernetes:
kubectl apply -f k8s/deployment.yaml
List the deployments and pods:
kubectl get deployments
kubectl get pods
Display some more information:
kubectl describe deployment hello
kubectl describe pod hello
Show the application logs:
kubectl logs -l app=hello
# It is also possible to get the logs for a particular pod, given its name:
kubectl logs <pod-name>
Connecting to a pod:
kubectl exec <pod-name> -it -- sh
Update k8s/deployment.yaml
so that the deployment uses two replicas:
# ...
spec:
# ...
replicas: 2
# ...
And then apply the configuration again:
kubectl apply -f k8s/deployment.yaml
Listing the pods must now show two pods for application hello
:
kubectl get pods -l app=hello
kubectl apply -f k8s/service.yaml
List the services in the cluster:
kubectl get services
Find some more information about the created service:
kubectl describe service hello
In a traditional Kubernetes cluster the external IP would be shown. In Minikube, however, the external IP must be obtained by running:
minikube service hello --url
Use curl
to verify you can access the application:
curl $(minikube service hello --url)
Use the external address of the EC2 instance (not the one for the service) to access the application from your browser: http://ec2-<external-IP>.eu-west-1.compute.amazonaws.com:<port>
Get the dashboard's port running the following command:
minikube dashboard --url
Then use that port together with the external address of the EC2 instance to access the dashboard.
Explore the different resources in the cluster (pods, deployments, services, etc.).
Change main.py
so that it returns another message, and then create a new docker image with a new tag:
sudo docker build -t hello:0.2 .
Now, update deployment.yaml
so that it uses image hello:0.2
. After that, update the deployment using:
kubectl apply -f k8s/deployment.yaml
Use your browser to check whether the message has changed.
Change main.py
so that the healthz
endpoint returns an error:
from flask import Flask, abort
# ...
@app.route('/healthz')
def healthz():
abort(500)
Create a new docker image:
sudo docker build -t hello:0.3 .
Update the deployment.yaml
file to use the new image, and update the deployment:
kubectl apply -f k8s/deployment.yaml
Watch pod status:
watch kubectl get pods
To rollback the deployment execute:
kubectl rollout undo deployment/hello
Create and deploy the cpu
application (this application performs a CPU-intensive operation when it receives a request):
cd ~/k8s-workshop/cpu
sudo docker build -t cpu:0.1 .
kubectl apply -f k8s
Run the following command to send traffic to the application:
while true; do curl $(minikube service cpu --url) ; done
After some seconds you should see an increase in CPU utilization. Then, the auto-scale mechanism will trigger, creating new replicas. Run the following command to see the new replicas being created:
watch kubectl get pods
To create a full-fledged Kubernetes cluster have a look at kops.