You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.2 KiB

  1. # Introduction to kubectl
  2. ## Deployment of the needed description in kubernetes
  3. These are two approaches to create the description in Kuberentes:
  4. ```bash
  5. # create a namespace
  6. kubectl create namespace web-test
  7. # Then choose one way:
  8. # (1) Create the description
  9. kubectl create -f nginx.yml -f service.yml
  10. # (2) Create or update descriptions if existing
  11. kubectl apply -f nginx.yml -f service.yml
  12. ```
  13. ## To show it is working
  14. Here are some useful commands:
  15. ```bash
  16. # show nodes
  17. kubectl get nodes
  18. # show pods for our namespace
  19. kubectl get -n web-test pods
  20. # show deployments for our namespace
  21. kubectl get -n web-test deployment
  22. # show services for our namespace
  23. kubectl show -n web-test service
  24. # show logs of deployed nginx instances
  25. kubectl logs -n web-test deployment/nginx-deployment
  26. ```
  27. ## Scaling up and down
  28. ```bash
  29. # scale up instances to 5
  30. kubectl scale deployment/nginx-deployment --replicas=5
  31. # scale down instances again to 3
  32. kubectl scale deployment/nginx-deployment --replicas=3
  33. ```
  34. ## To see it is working in the browser ;)
  35. The nginx instances are reachable at the floating ips of the **node**-instances at port **30007** in our case.
  36. ## Many other things can be done ;)
  37. - Autoscaling
  38. - Detailled Service functions (LoadBalancer, ...)
  39. - Dashboard
  40. - FaaS Setup ;)
  41. - ...
  42. ## Appendix
  43. ### Nginx description
  44. ```yml
  45. apiVersion: apps/v1
  46. kind: Deployment
  47. metadata:
  48. name: nginx-deployment
  49. namespace: web-test
  50. spec:
  51. selector:
  52. matchLabels:
  53. app: nginx-deployment
  54. replicas: 3 # tells deployment to run 3 pods matching the template
  55. template:
  56. metadata:
  57. labels:
  58. app: nginx-deployment
  59. spec:
  60. containers:
  61. - name: nginx
  62. image: nginx:latest
  63. ports:
  64. - containerPort: 80
  65. ```
  66. ### Nginx service description
  67. ```yml
  68. apiVersion: v1
  69. kind: Service
  70. metadata:
  71. name: nginx-service
  72. namespace: web-test
  73. spec:
  74. type: NodePort
  75. selector:
  76. app: nginx-deployment
  77. ports:
  78. # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
  79. - port: 80
  80. targetPort: 80
  81. # Optional field
  82. # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
  83. nodePort: 3000
  84. ```