5.3 Cheatsheet
https://killercoda.com/isislab/scenario/exam-playground
---[01] Resources that are namespaced
kubectl api-resources
---[02 Get namespaces ]
kubectl get namespaces
---[03] Get description of namespaces
kubectl describe ns default
---[04] Get description of services in namespaces
kubectl get svc --namespace kube-system
---[05] Create a namespace
git clone https://github.com/nigelpoulton/TheK8sBook.git #clone repo
cd TheK8sBook/namespaces
kubectl create ns hydra #imperative
kubectl get ns
cat shield-ns.yml
Here are data in shield-ns.yml
kind: Namespace
apiVersion: v1
metadata:
name: shield
labels:
env: marvel
kubectl apply -f shield-ns.yml
kubectl get ns # see namespaces
kubectl delete ns hydra # for other examples
kubectl get ns
kubectl config set-context --current --namespace shield # set kubectl for a specific Namespace
kubectl get pods #empty
---[06] Get description of services in namespaces
less app.yml
kubectl apply -f app.yml #warning
kubectl get pods -n shield # take a look at the pods there
kubectl get pods # it is enough (as the current is set to shield)
kubectl get svc -n shield # external-up is always <pending>
kubectl describe services the-bus # to get the CLUSTER-IP (EXTERNAL-IP is always pending) as xxx.xxx.xxx.xxx
curl xxx.xxx.xxx.xxx:8080 # you get the AOS answer
kubectl delete ns shield # deletes everything inside ns
kubectl get ns # in another terminal to see it terminating
kubectl config set-context --current --namespace default # reset current to default
---[07] Sidecar initialization
cd ~/TheK8sBook/pods
vim sidecarpod.yml
On the browser
1: Fork in your Github https://github.com/nigelpoulton/ps-sidecar and call it my-ps-sidecar
---[08] Sidecar running
- Update the YAML file with the URL of your forked repo
vim sidecarpod.yml
Change the repository in GIT_SYNC_REPO from
value: https://github.com/nigelpoulton/ps-sidecar.git
To
value: https://github.com/vitsca/my-ps-sidecar.git
vitsca/my-ps-sidecar/
- Deploy the app
kubectl apply -f sidecarpod.yml
kubectl get pods # to see them
kubectl describe pods # to see them
- Connect to the app and see it display This is version 1.0
kubectl get svc
Get the address CLUSTER-IP xxx.xxx.xxx.xxx
curl xxx.xxx.xxx.xxx
see that it is indeed answering 1.0
---[09] Sidecar changed the content
- Make a change to your fork of the GitHub repo
---[10] Make a new call and see how to sidecar updated the data
- Call again the sidecar nginx and see it changed
curl xxx.xxx.xxx.xxx