当前位置:  首页>> 技术小册>> Kubernets合辑2-部署Ingress

部署控制器的方式有两种:
● 使用deployment + service(NodePort/LoadBalancer)
● 使用daemonset
一般情况,在私有云环境中,更加推荐使用daemonset,在公有云可以使用 deployment。这里以daemon为例:

  1. [root@maxiaoke nginxinc-ingress]# kubectl label nodes ubuntu-2004-104 ingress-controller/nginx=yes
  2. [root@maxiaoke nginxinc-ingress]# kubectl label nodes ubuntu-2004-105 ingress-controller/nginx=yes
  3. [root@maxiaoke nginxinc-ingress]# kubectl label nodes ubuntu-2004-106 ingress-controller/nginx=yes
  4. [root@maxiaoke nginxinc-ingress]# kubectl apply -f daemon-set/nginx-ingress.yaml

daemon-set/nginx-ingress.yaml:

  1. apiVersion: apps/v1
  2. kind: DaemonSet
  3. metadata:
  4. name: nginx-ingress
  5. namespace: nginx-ingress
  6. spec:
  7. selector:
  8. matchLabels:
  9. app: nginx-ingress
  10. template:
  11. metadata:
  12. labels:
  13. app: nginx-ingress
  14. #annotations: # 如果prometheus是通过注释采集日志,则需要打开
  15. #prometheus.io/scrape: "true"
  16. #prometheus.io/port: "9113"
  17. #prometheus.io/scheme: http
  18. spec:
  19. serviceAccountName: nginx-ingress
  20. containers:
  21. - image: nginx/nginx-ingress:2.2.0 # 不带链路追踪的镜像,链路跟踪后续演示
  22. imagePullPolicy: IfNotPresent
  23. name: nginx-ingress
  24. ports:
  25. - name: http
  26. containerPort: 80
  27. hostPort: 80
  28. - name: https
  29. containerPort: 443
  30. hostPort: 443
  31. - name: readiness-port
  32. containerPort: 8081
  33. - name: prometheus
  34. containerPort: 9113
  35. readinessProbe:
  36. httpGet:
  37. path: /nginx-ready
  38. port: readiness-port
  39. periodSeconds: 1
  40. securityContext:
  41. allowPrivilegeEscalation: true
  42. runAsUser: 101 #nginx
  43. capabilities:
  44. drop:
  45. - ALL
  46. add:
  47. - NET_BIND_SERVICE
  48. env:
  49. - name: POD_NAMESPACE
  50. valueFrom:
  51. fieldRef:
  52. fieldPath: metadata.namespace
  53. - name: POD_NAME
  54. valueFrom:
  55. fieldRef:
  56. fieldPath: metadata.name
  57. - name: TZ # 指定时区,方便查看日志
  58. value: Asia/Shanghai
  59. args:
  60. - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
  61. - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
  62. - -wildcard-tls-secret=$(POD_NAMESPACE)/default-server-secret # 指定默认证书,当ingress中声明TLS却没有指定secretName时使用该证书
  63. - -enable-prometheus-metrics # 启用prometheus指标
  64. - -enable-snippets # 支持通过注释插入代码片段
  65. - -health-status # 开启健康状态检查接口,方便前端LB对它健康检查
  66. - -enable-latency-metrics # 开启延迟指标监控
  67. nodeSelector:
  68. ingress-controller/nginx: "yes" # 选择部署的节点,即使是daemonset也不是所有worker节点都部署

该分类下的相关小册推荐: