|
| 1 | +# Use kubectl in the devops-toolkit |
| 2 | + |
| 3 | +## Kubernetes document |
| 4 | + |
| 5 | +Some document to help you start with kubernetes (k8s) |
| 6 | + |
| 7 | +- <https://kubernetes.io/docs/home/> |
| 8 | +- <https://github.com/tungbq/devops-basic/tree/main/topics/k8s> |
| 9 | + |
| 10 | +To use the existing container instead of creating one, use `docker exec` command instead of `docker run` |
| 11 | + |
| 12 | +```bash |
| 13 | +docker exec -it my_devops_toolkit /bin/bash |
| 14 | +``` |
| 15 | + |
| 16 | +## Use case 1: Use kubeconfig from the host |
| 17 | + |
| 18 | +Mount the `.kube/config` file from the host to container |
| 19 | + |
| 20 | +```bash |
| 21 | +docker run --rm --network host -it -v ~/.kube/config:/root/.kube/config devops-toolkit:latest |
| 22 | +############################################### |
| 23 | +# Now we are in the docker container terminal # |
| 24 | +############################################### |
| 25 | +kubectl get nodes |
| 26 | + |
| 27 | +# Deploy application |
| 28 | +kubectl apply -f https://k8s.io/examples/application/deployment.yaml |
| 29 | +# View the pod |
| 30 | +kubectl get pods -w |
| 31 | +# View the deployment |
| 32 | +kubectl get deployment |
| 33 | +# More command as per your need... |
| 34 | +``` |
| 35 | + |
| 36 | +Sample Result |
| 37 | + |
| 38 | +```bash |
| 39 | +➜ ~ docker run --rm --network host -it -v ~/.kube/config:/root/.kube/config devops-toolkit:latest |
| 40 | +root@docker-desktop:~# kubectl get nodes |
| 41 | +NAME STATUS ROLES AGE VERSION |
| 42 | +kind-control-plane Ready control-plane 21m v1.29.2 |
| 43 | +root@docker-desktop:~# kubectl apply -f https://k8s.io/examples/application/deployment.yaml |
| 44 | +deployment.apps/nginx-deployment unchanged |
| 45 | +root@docker-desktop:~# kubectl get pods -w |
| 46 | +NAME READY STATUS RESTARTS AGE |
| 47 | +nginx-deployment-86dcfdf4c6-c2cfp 1/1 Running 0 99s |
| 48 | +nginx-deployment-86dcfdf4c6-w4vp7 1/1 Running 0 99s |
| 49 | +root@docker-desktop:~# kubectl get deployment |
| 50 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 51 | +nginx-deployment 2/2 2 2 115s |
| 52 | +``` |
| 53 | + |
| 54 | +## Troubleshooting |
| 55 | + |
| 56 | +- For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md) |
0 commit comments