Create a local Kubernetes cluster, e.g. k3d with 3 worker nodes
k3d cluster create -p 8080:80@loadbalancer --agents 3
k3d cluster start
kubectl config use-context k3d-k3s-default
or use kubectx
kubectx k3d-k3s-default
kubectl create namespace demo
or
kubectl create -f 00-namepace.yaml
kubectl config set-context --current --namespace=demo
or use kubens (comes with kubectx)
kubens demo
watch kubectl get all --namespace demo
kubectl create -f 01-deployment.yaml
kubectl create -f 02-service.yaml
create a port-forward directly to the service port:
kubectl port-forward svc/hello 8888:8000
and execute in another terminal
curl localhost:8888
Create an ingress to expose the service to the internet (needs an Ingress controller - K3d has a bundled Traefik)
kubectl create -f 03-ingress.yaml
curl -H "host:echo.com" localhost:8080
Should get the response You've hit hello-<ID> version:1
Look at the logs
kubectl logs -f deploy/hello
kubectl scale deployment hello --replicas 5
Look at the logs
kubectl logs -f deploy/hello
or use stern to see the logs from all the pods
stern hello
Edit the deployment directly on k8s
kubectl edit deploy hello
Set image to marcoamador/hello:1.0.1
curl -H "host:echo.com" localhost:8080
The response must be now You've hit hello-<ID> version:1.0.1
kubectl create -f 04-configmap.yaml
kubectl create -f 05-deployment-configmap.yaml
kubectl exec -it hello-configmap-<ID> -- sh
# env
or
kubectl exec hello-configmap-<ID> -- env
kubectl create -f 06-secret.yaml
kubectl create -f 07-deployment-secret.yaml
and "see" the secret:
kubectl exec hello-secret-<ID> -- env | grep SECRET_
kubectl create -f 08-job.yaml
kubectl create -f 09-cronjob.yaml
Look at the logs
kubectl logs -f countdown-<ID>
or
kubectl logs -f job/countdown
kubectl create -f 10-daemonset.yaml
kubectl create -f 11-service-ds.yaml
kubectl create -f 12-ingress-ds.yaml
curl -H "host:echo-ds.com" localhost:8080
kubectl create -f 13-deployment-sidecar.yaml
see the logs from main container and sidecar in terminals side by side
sidecar cache proxy
kubectl logs -f deploy/hello-sidecar --container vache-proxy
the container with our API to be cached
kubectl logs -f deploy/hello-sidecar --container hello
or use stern
stern hello-sidecar --container vache-proxy
stern hello-sidecar --container hello
both container in same log:
stern hello-sidecar
make some requests (repeat them to see that the requests are cached for 15 secs):
curl -H "host:echo-sidecar.com" http://localhost:8080/something/1
curl -H "host:echo-sidecar.com" http://localhost:8080/something/2
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
kubectl apply -f 14-dashboard-admin-user.yaml
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
kubectl proxy
./delete-all.sh
k3d cluster stop
k3d cluster delete