Configuring HTTPS Backend Services for an Nginx Ingress
Ingress can function as a proxy for backend services using different protocols. By default, the backend proxy channel of an ingress is an HTTP channel. To create an HTTPS channel, add the following configuration to the annotations field:
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
An ingress configuration example is as follows:
- Use kubectl to access the cluster. For details, see Accessing a Cluster Using kubectl.
- Create a YAML file named ingress-test.yaml. The file name can be customized.vi ingress-test.yaml
For clusters of v1.23 or later:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: ingress-testnamespace: defaultannotations:nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"spec:tls:- secretName: ingress-test-secret # Replace it with your TLS key certificate.rules:- host: ''http:paths:- path: '/'backend:service:name: <your_service_name> # Replace it with the name of your target Service.port:number: <your_service_port> # Replace it with the port number of your target Service.property:ingress.beta.kubernetes.io/url-match-mode: STARTS_WITHpathType: ImplementationSpecificingressClassName: nginxFor clusters of v1.21 or earlier:
apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:name: ingress-testnamespace: defaultannotations:kubernetes.io/ingress.class: nginxnginx.ingress.kubernetes.io/backend-protocol: "HTTPS"spec:tls:- secretName: ingress-test-secret # Replace it with your TLS key certificate.rules:- host: ''http:paths:- path: '/'backend:serviceName: <your_service_name> # Replace it with the name of your target Service.servicePort: <your_service_port> # Replace it with the port number of your target Service. - Create an ingress.kubectl create -f ingress-test.yaml
If information similar to the following is displayed, the ingress has been created:
ingress/ingress-test created - Check the created ingress.kubectl get ingress
If information similar to the following is displayed, the ingress has been created:
NAME CLASS HOSTS ADDRESS PORTS AGEingress-test nginx * 121.**.**.** 80 10s
Parent topic: Advanced Setting Examples of Nginx Ingresses