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

  1. # 创建默认的Nginx Server证书,该证书用于针对404页面响应和默认TLS证书。nginx默认提供了自签名证书 common/default-server-secret.yaml, 但是更加推荐使用自己的公司证书。
  2. [root@maxiaoke nginxinc-ingress]# kubectl create secret -n nginx-ingress tls default-server-secret --cert=certs/server.crt --key=certs/server.key
  3. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/nginx-config.yaml
  4. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/ingress-class.yaml
  5. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml
  6. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml
  7. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml
  8. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/crds/k8s.nginx.org_policies.yaml
  9. [root@maxiaoke nginxinc-ingress]# kubectl apply -f common/crds/k8s.nginx.org_globalconfigurations.yaml

common/nginx-config.yaml:

  1. # nginx 的自定义配置项,默认data为空
  2. kind: ConfigMap
  3. apiVersion: v1
  4. metadata:
  5. name: nginx-config
  6. namespace: nginx-ingress
  7. data:
  8. client-max-body-size: 10m
  9. error-log-level: error
  10. keepalive: "8"
  11. server-tokens: "false"
  12. ssl-protocols: TLSv1.2
  13. worker-connections: "10240"
  14. worker-processes: "2"
  15. # 当前环境的ingress controller下游是使用Nginx L4负载均衡的,为了获取到源地址,使用了 proxy protocol协议
  16. # 因此打开了 proxy-protocol,并且日志中也指定了proxy_protocol_addr
  17. # 如果下游LB可以透传地址到当前控制器,可以取消 proxy_protocol配置
  18. proxy-protocol: "true"
  19. real-ip-header: "proxy_protocol"
  20. location-snippets: |
  21. proxy_set_header X-Real-IP $proxy_protocol_addr;
  22. log-format: '$time_local|$remote_addr|$proxy_protocol_addr|$http_x_real_ip|$http_x_forwarded_for|$resource_name|$resource_type|$resource_namespace|$service|$request_method|$server_protocol|$host|$request_uri|$http_referer|$http_user_agent|$body_bytes_sent|$status|$grpc_status'

common/ingress-class.yaml:

  1. apiVersion: networking.k8s.io/v1
  2. kind: IngressClass
  3. metadata:
  4. name: nginx
  5. # 设置为默认的ingress class,如果注释annotations,表示不会设置为默认的ingress controller
  6. annotations:
  7. ingressclass.kubernetes.io/is-default-class: "true"
  8. spec:
  9. controller: nginx.org/ingress-controller

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