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.

114 lines
2.3 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 of the following ways:
  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 get -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. *nginx.yml:*
  45. ```yml
  46. apiVersion: apps/v1
  47. kind: Deployment
  48. metadata:
  49. name: nginx-deployment
  50. namespace: web-test
  51. spec:
  52. selector:
  53. matchLabels:
  54. app: nginx-deployment
  55. replicas: 3 # tells deployment to run 3 pods matching the template
  56. template:
  57. metadata:
  58. labels:
  59. app: nginx-deployment
  60. spec:
  61. containers:
  62. - name: nginx
  63. image: nginx:latest
  64. ports:
  65. - containerPort: 80
  66. ```
  67. ### Nginx service description
  68. *service.yml:*
  69. ```yml
  70. apiVersion: v1
  71. kind: Service
  72. metadata:
  73. name: nginx-service
  74. namespace: web-test
  75. spec:
  76. type: NodePort
  77. selector:
  78. app: nginx-deployment
  79. ports:
  80. # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
  81. - port: 80
  82. targetPort: 80
  83. # Optional field
  84. # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
  85. nodePort: 30007
  86. ```