Home > Software engineering >  kubernetes force service to use https
kubernetes force service to use https

Time:12-18

I want to expose k8s api's using a service. My issue is that the api only respond on port 6443 on https. Any attempt on http return status 400 bad request. How can I "force" the service to user https ?

apiVersion: v1
kind: Service
metadata:
  name: k8s-api
  namespace: kube-system
  labels:
    label: k8s-api
spec:
  ports:
  - port: 80 #Port on which your service is running
    targetPort: 6443
    protocol: TCP
    name: http
  selector:
    name: kube-apiserver-master-node 

May be this ?

apiVersion: v1
kind: Service
metadata:
  name: k8s-api
  namespace: kube-system
  labels:
    label: k8s-api
spec:
  ports:
  - port: 443 #Port on which your service is running
    targetPort: 6443
    protocol: TCP
    name: http
  selector:
    name: kube-apiserver-master-node 

CodePudding user response:

If you are using the Nginx ingress by default it does SSL off load and sends plain HTTP in the background.

Changing port 6443 might be helpful if you request direct connecting to the service.

If you are using the Nginx ingress make sure it doesn't terminate SSL.

nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
  • Related