Home > database >  Localhost kubernetes ingress not exposing services to local machine
Localhost kubernetes ingress not exposing services to local machine

Time:09-02

I'm running kuberenetes in localhost, the pod is running and I can access the services when I port forwarding:

kubectl port-forward svc/my-service 8080:8080

I can get/post etc. the services in localhost.

I'm trying to use it with ingress to access it, here is the yml file:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: my-ingress
spec:
    ingressClassName: nginx
    rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
              service:
                  name: my-service
                  port:
                      number: 8080

I've also installed the ingress controller. But it isn't working as expected. Anything wrong with this?

EDIT: the service that Im trying to connect with ingress:

apiVersion: apps/v1
kind: Deployment
metadata:
    name: my-service
    labels:
        app: my-service
spec:
    replicas: 1
    selector:
        matchLabels:
            app: my-service
    template:
        metadata:
            labels: my-service
                app: my-service
        spec:
            containers:
            - image: test/my-service:0.0.1-SNAPSHOT
              name: my-service
              ports:
                  - containerPort:8080
       ... other spring boot override properties

---

apiVersion: v1
kind: Service
metadata:
    name: my-service
    labels:
        app: my-service
spec:
    type: ClusterIP
    selector:
        app: my-service
    ports:
    - name: 8080-8080
      port: 8080
      protocol: TCP
      targetPort: 8080

service is working by itself though

EDIT:

It worked when I used https instead of http

CodePudding user response:

Is ingress resource in the same namespace as the service? Can you share the manifest of service? Also, what do logs of nginx ingress-controller show and what sort of error do you face when hitting the endpoint in the browser?

Ingress's YAML file looks OK to me BTW.

CodePudding user response:

I was being stupid. It worked when I used https instead of http

  • Related