In the following lab we will set up our local development environment, provision the workshop cluster and roll out our static web application example with an additional sidecar and init-container. Your deployment won't be exposed and is only available by ClusterIP of the corresponding pod-service. You can access the application by tunneling your localhost through kubectl proxy
command, or kubectl port-forward
.
- Run deployment
kubectl apply -f .
- You can check the state of Pods at any time with the following kubectl command:
kubectl get pods -n doit-lab-02
- You can also permanently display the current log stream of the pod in question in your terminal using the following command:
# logs of static web application (container=001-static-web-app-c)
kubectl logs -f -l k8s-app=static-web-app-advanced -n doit-lab-02 -c 001-static-web-app-c
# logs of web applications sidecar (container=002-static-web-app-sidecar-c)
kubectl logs -f -l k8s-app=static-web-app-advanced -n doit-lab-02 -c 002-static-web-app-sidecar-c
# logs of the pods init container (container=000-static-web-app-advanced-init-c)
kubectl logs -f -l k8s-app=static-web-app-advanced -n doit-lab-02 -c 000-static-web-app-advanced-init-c
- You can access this pod from your local environment using kubectl port-forwarding & access the app by hitting url
http://localhost:8080
kubectl port-forward pod/static-web-app-advanced 8080:80 -n doit-lab-02
- You can also jump directly into a sh-terminal of the started pod
# static web application (container=001-static-web-app-c)
kubectl exec -it static-web-app-advanced -c 001-static-web-app-c -n doit-lab-02 -- sh
# web applications sidecar (container=002-static-web-app-sidecar-c, will run for 60s)
kubectl exec -it static-web-app-advanced -c 002-static-web-app-sidecar-c -n doit-lab-02 -- sh
Now we can set the current k8s context to our lab exercise namespace doit-lab-02
to make sure that every command set is run against this lab resources.
kubectl config set-context --current --namespace=doit-lab-02
kubectl delete -f .