NGINX Ingress Controller and configures it to use port 9443 for HTTPS
To configure Kubernetes Ingress to handle HTTPS traffic on port 9443, follow these steps. This guide assumes you already have a Kubernetes cluster and Ingress controller set up.
Prerequisites
- Kubernetes Cluster: Ensure you have a running Kubernetes cluster.
- Ingress Controller: Make sure an Ingress controller (e.g., NGINX Ingress Controller) is installed and running in your cluster.
- SSL Certificate: Obtain an SSL certificate (can be from a CA or self-signed).
Steps
Install and Configure Ingress Controller
If not already installed, install an NGINX Ingress Controller. You can use Helm for this:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.service.ports.https=9443
This command installs the NGINX Ingress Controller and configures it to use port 9443 for HTTPS.
Create a Namespace (optional)
kubectl create namespace ingress-nginx
Create an SSL Certificate Secret
Convert your SSL certificate and key into a Kubernetes secret:
kubectl create secret tls <secret-name> --cert=<path-to-cert> --key=<path-to-key> -n ingress-nginx
Replace
<secret-name>
,<path-to-cert>
, and<path-to-key>
with your secret name and the path to your certificate and key files.Create an Ingress Resource
Define an Ingress resource to route traffic to your application. This Ingress will use the secret created above for TLS termination.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress namespace: ingress-nginx annotations: nginx.ingress.kubernetes.io/ssl-redirect: "true" nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" spec: tls: - hosts: - example.com secretName: <secret-name> rules: - host: example.com http: paths: - path: / pathType: Prefix backend: service: name: example-service port: number: 80
Replace
example.com
with your domain,example-service
with your Kubernetes service name, and<secret-name>
with the name of the secret you created.Configure Ingress Controller Service
Ensure the Ingress controller service is listening on port 9443. Edit the service to reflect this:
kubectl edit svc <nginx-ingress-controller-service-name> -n ingress-nginx
Change the ports section to include port 9443:
ports: - name: https port: 9443 targetPort: 8443
Verify the Configuration
Ensure that the Ingress controller is properly routing traffic to your application on port 9443. You can test it using
curl
:curl -k https://example.com:9443
The
-k
flag is used to skip SSL verification if using a self-signed certificate.
Notes
- Ensure your DNS is correctly configured to point to your Ingress controller's external IP.
- If you are using a cloud provider's Ingress controller, the setup might vary slightly based on the provider's requirements and configurations.
- You can also use Let's Encrypt for SSL certificates and automate the process using cert-manager.
By following these steps, you can configure Kubernetes Ingress to handle HTTPS traffic on port 9443.
댓글
댓글 쓰기