当前位置:   article > 正文

helm 安装ingress nginx 4.5.2_helm安装ingress-nginx修改配置文件

helm安装ingress-nginx修改配置文件

目录

前期准备

开始安装

1.下载安装包和helm工具

2. 解压文件并配置helm

3. 修改nginx配置文件(只记录修改的部分)

4. 安装ingress nginx

5. 测试


前期准备

ingress-nginx-4.5.2.tgz:ingress nginx安装包

helm-v3.11.1-linux-amd64.tar.gz: helm 工具

lvs集群

开始安装

1.下载安装包和helm工具

  1. ingress ingress 安装包
  2. github地址:https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-4.5.2/ingress-nginx-4.5.2.tgz
  3. wget -P /opt/k8s-install/ http://10.120.175.36/ingress-nginx-4.5.2.tgz #我将安装包放在了内网
  4. helm 工具包
  5. wget -P /opt/k8s-install/ http://10.120.175.36/helm-v3.11.1-linux-amd64.tar.gz

2. 解压文件并配置helm

  1. 解压并改名
  2. cd /opt/k8s-install/
  3. tar -xf ingress-nginx-4.5.2.tgz
  4. mv ingress-nginx ingress-yidian-inc-nginx1
  5. 解压helm
  6. tar xf helm-v3.11.1-linux-amd64.tar.gz
  7. mv linux-amd64/helm /bin/
  8. 测试
  9. [root@l-shake-k8s-master1 package]$ helm version
  10. version.BuildInfo{Version:"v3.11.1", GitCommit:"293b50c65d4d56187cd4e2f390f0ada46b4c4737", GitTreeState:"clean", GoVersion:"go1.18.10"}

3. 修改nginx配置文件(只记录修改的部分)

修改values文件
vim /opt/k8s-install/ingress-nginx/ingress-yidian-inc-nginx1/values.yaml 
  1. registry: harbor-sh.yidian-inc.com #修改为自己的私有仓库地址
  2. image: ingress-nginx/controller #镜像路径和名称
  3. tag: "v1.6.4" #镜像tag
  4. #digest: sha256:15be4666c53052484dd2992efacf2f50ea77a78ae8aa21ccd91af6baaa7ea22f #注释掉
  5. hostNetwork: true
  6. priorityClassName: high-priority
  7. config: #增加优化配置项,实际有很多参数都有默认参数,根据实际情况进行修改
  8. # nginx 与 client 保 持 的 一 个 长 连 接 能 处 理 的 请 求 数 量 , 默 认 100, 高 并 发 场 景 建 议 调 高 。
  9. # 参 考 : https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#keep-alive-requests
  10. keep-alive-requests: "10000"
  11. # nginx 与 upstream 保 持 长 连 接 的 最 大 空 闲 连 接 数 (不 是 最 大 连 接 数 ), 默 认 32, 在 高 并 发 下 场 景 下 调 大 , 避 免 频 繁 建 连 导 致 TIME_WAIT 飙 升 。
  12. # 参 考 : https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#upstream-keepalive-connections
  13. upstream-keepalive-connections: "200"
  14. # 每 个 worker 进 程 可 以 打 开 的 最 大 连 接 数 , 默 认 16384。
  15. # 参 考 : https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#max-worker-connections
  16. max-worker-connections: "65536"
  17. #每 个 work可 以 打 开 的 最 大 文 件 数 , 默 认 0.
  18. #参 考 : http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile
  19. max-worker-open-files: "655350"
  20. #参 考 : http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity
  21. worker-cpu-affinity: "auto"
  22. #参 考 : http://nginx.org/en/docs/ngx_core_module.html#worker_processes
  23. worker-processes: "auto"
  24. #参 考 :
  25. server-tokens: "false"
  26. # http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type
  27. default-type: "application/octet-stream"
  28. #https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#custom-http-errors
  29. #custom-http-errors: "503,504"
  30. #log
  31. access-log-path: "/var/log/nginx/nginx-access.log"
  32. error-log-path: "/var/log/nginx/nginx-error.log"
  33. #全 局 禁 用 308重 定 向
  34. ssl-redirect: "false"
  35. #禁 用 geoip
  36. use-geoip: "false"
  37. server-name-hash-bucket-size: "128"
  38. client-body-timeout: "60"
  39. client-header-buffer-size: "8k"
  40. large-client-header-buffers: "4 32k"
  41. proxy-body-size: "256m"
  42. client-body-buffer-size: "128k"
  43. http2-max-concurrent-streams: "64"
  44. http2-max-field-size: "16k"
  45. keep-alive: "30"
  46. proxy-connect-timeout: "15"
  47. proxy-send-timeout: "60"
  48. proxy-read-timeout: "60"
  49. proxy-buffer-size: "128k"
  50. proxy-buffers-number: "32"
  51. proxy-headers-hash-max-size: "51200"
  52. proxy-headers-hash-bucket-size: "6400"
  53. proxy-next-upstream: "error timeout http_500 http_502 http_503 http_504"
  54. use-gzip: "true"
  55. gzip-min-length: "1000"
  56. gzip-level: "1"
  57. gzip-types: "text/plain application/x-javascript text/css application/xml application/json"
  58. ssl-protocols: "TLSv1 TLSv1.1 TLSv1.2"
  59. ssl-ciphers: "ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:AES256+EDH"
  60. ssl-buffer-size: "16k"
  61. ssl-session-cache: "true"
  62. ssl-session-timeout: "5m"
  63. ssl-dh-param: "/etc/nginx/pem/dhparam.pem"
  64. log-format-upstream: "$time_local|$hostname|$remote_addr|$upstream_addr|$request_time|$upstream_response_time|$upstream_connect_time|$status|$upstream_status|-|$bytes_sent|$body_bytes_sent|-|$request|$http_user_agent|$http_refere
  65. r|^_^|$scheme|$request_method|$request_id|-|^_^|-|$cookie_jsessionid"
  66. dnsPolicy: ClusterFirstWithHostNet #在k8s的网络中解析service name
  67. ingressClassResource:
  68. # -- Name of the ingressClass
  69. name: ingress-yidian-inc-nginx1 #ingress Class名称
  70. ingressClass: ingress-yidian-inc-nginx1
  71. kind: DaemonSet #DaemonSet方式部署
  72. #一定要修改,不然就会出现一个控制器管理多组nginx 代理层,配置都会创建多份(ingress nginx的个数),也会导致controller有瓶颈风险
  73. controllerValue: "k8s.io/ingress-yidian-inc-nginx1"
  74. nodeSelector: #设置部署nginx 匹配标签
  75. kubernetes.io/os: linux
  76. ingress-yidian-inc-nginx1: "true"
  77. patch:
  78. enabled: true
  79. image:
  80. registry: harbor-sh.yidian-inc.com
  81. image: ingress-nginx/kube-webhook-certgen
  82. tag: v1.6.4
  83. #digest: sha256:39c5b2e3310dc4264d638ad28d9d1d96c4cbb2b2dcfb52368fe4e3c63f61e10f #注释掉

设置优先级

nginx-controller-priority.yaml

  1. apiVersion: scheduling.k8s.io/v1
  2. kind: PriorityClass
  3. metadata:
  4. name: high-priority
  5. value: 1000000000
  6. globalDefault: false
  7. description: "This priority class should be used for nginx-ingress-controller service pods only."
kubectl apply -f nginx-controller-priority.yaml

4. 安装ingress nginx

给节点打标签

  1. kubectl label node 10.120.129.10 ingress-yidian-inc-nginx1=true
  2. kubectl label node 10.120.129.11 ingress-yidian-inc-nginx1=true
  1. 安装ingress nginx
  2. helm install ingress-yidian-inc-nginx1 -f values.yaml -n ingress-yidian-inc-nginx1 .
  3. 执行后会出现如下提示
  4. [root@l-shake-k8s-master1 ingress-yidian-inc-nginx1]$ helm install ingress-yidian-inc-nginx1 -f values.yaml -n ingress-yidian-inc-nginx1 .
  5. NAME: ingress-yidian-inc-nginx1
  6. LAST DEPLOYED: Mon Mar 6 11:03:24 2023
  7. NAMESPACE: ingress-yidian-inc-nginx1
  8. STATUS: deployed
  9. REVISION: 1
  10. TEST SUITE: None
  11. NOTES:
  12. The ingress-nginx controller has been installed.
  13. It may take a few minutes for the LoadBalancer IP to be available.
  14. You can watch the status by running 'kubectl --namespace ingress-yidian-inc-nginx1 get services -o wide -w ingress-yidian-inc-nginx1-ingress-nginx-controller'
  15. An example Ingress that makes use of the controller:
  16. apiVersion: networking.k8s.io/v1
  17. kind: Ingress
  18. metadata:
  19. name: example
  20. namespace: foo
  21. spec:
  22. ingressClassName: ingress-yidian-inc-nginx1
  23. rules:
  24. - host: www.example.com
  25. http:
  26. paths:
  27. - pathType: Prefix
  28. backend:
  29. service:
  30. name: exampleService
  31. port:
  32. number: 80
  33. path: /
  34. # This section is only required if TLS is to be enabled for the Ingress
  35. tls:
  36. - hosts:
  37. - www.example.com
  38. secretName: example-tls
  39. If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:
  40. apiVersion: v1
  41. kind: Secret
  42. metadata:
  43. name: example-tls
  44. namespace: foo
  45. data:
  46. tls.crt:
  47. tls.key:
  48. type: kubernetes.io/tls
  49. [root@l-shake-k8s-master1 ingress-yidian-inc-nginx1]$ kubectl get ingressclasses.networking.k8s.io
  50. NAME CONTROLLER PARAMETERS AGE
  51. ingress-yidian-inc-nginx1 k8s.io/ingress-nginx 113m
  52. ingress nginx 卸载
  53. helm uninstall ingress-yidian-inc-nginx1 -n ingress-yidian-inc-nginx1

5. 测试

kubectl apply -f nginx.yaml
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: my-deploy-nginx
  5. namespace: default
  6. spec:
  7. replicas: 2
  8. selector:
  9. matchLabels:
  10. app: mynginx
  11. template:
  12. metadata:
  13. labels:
  14. app: mynginx
  15. spec:
  16. containers:
  17. - name: mynginx
  18. image: harbor-sh.yidian-inc.com/kubernetes-1.26.1/nginx
  19. ports:
  20. - containerPort: 80
  21. ---
  22. kind: Service
  23. apiVersion: v1
  24. metadata:
  25. name: myservice
  26. namespace: default
  27. spec:
  28. ports:
  29. - protocol: TCP
  30. port: 80
  31. targetPort: 80
  32. selector:
  33. app: mynginx
  34. type: ClusterIP
  35. ---
  36. apiVersion: networking.k8s.io/v1
  37. kind: Ingress
  38. metadata:
  39. name: mynginx
  40. namespace: default # 指 定 ingress的 命 名 空 间 , 害 怕 与 其 它 Pod IP冲 突
  41. spec:
  42. ingressClassName: "ingress-yidian-inc-nginx1" #在 部 署 ingress-nginx时 , valume.yaml文 件 中 定 义 的
  43. rules:
  44. - host: sunwenbo-nginx.yidian-inc.com
  45. http:
  46. paths:
  47. - path: /
  48. pathType: Prefix
  49. backend:
  50. service:
  51. name: myservice
  52. port:
  53. number: 80

绑定hosts进行访问测试

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/40735
推荐阅读
相关标签
  

闽ICP备14008679号