So I exposed my kubernetes api through service using the following command.
kubectl -n kube-system expose pod kube-apiserver-master-node --name=apiserver --port 6443
When I describe the service I get this
Name: apiserver
Namespace: kube-system
Labels: component=kube-apiserver
tier=control-plane
Annotations: <none>
Selector: component=kube-apiserver,tier=control-plane
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.105.200.112
IPs: 10.105.200.112
Port: <unset> 6443/TCP
TargetPort: 6443/TCP
Endpoints: 10.0.0.130:6443
Session Affinity: None
Events: <none>
Which seems to indicate that the service is running ok. Then I ran this yml to add my ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: main-ingress
namespace: kube-system
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
tls:
- hosts:
- k8s.domain.com
secretName: domain-tls
rules:
- host: "k8s.domain.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: apiserver
port:
number: 6443
But when I try to browse the k8s.domain.com it doesn't work it give me a bad request (400). I also tried with port 80 on the ingress config but it doesn't work either it gives me a 503. I think I'm missing something. I've seen this question but it doesn't talk about how to expose the service through ingress.