0
votes

I have a bare-metal kubernetes cluster. I applied the kubernetes nginx deployment like this: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/baremetal/deploy.yaml

and added this ingress resource:

apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  selector:
    app: ingress-nginx
    name: ingress-nginx
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: http
    - name: https
      port: 443
      targetPort: https

And my ingress resource:

apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
    - host: ** master hostname **
      http:
        paths:
          - path: /rest/endpoints/hello
            backend:
              serviceName: microservices-service
              servicePort: 8085
          - path: /rest/endpoints/calculateIterationTotalCapcity
            backend:
              serviceName: microservices-service
              servicePort: 8085

But still I can't access my master on port 80. Can you please help? Thanks in advance.

2
Could you please provide information on the error like how you are trying to connect and what error you are seeing. Also could you please provide more information on microservices-service service definition. - Kiruba

2 Answers

1
votes

From attached information we can see that your service definition is improper due to:

selector:
    app: ingress-nginx

As you can see in the original service definition for Bare-metal installation using NodePort it should looks like:

spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/component: controller

Note:

Service resources - In Kubernetes, a Service is an abstraction which defines a logical set of Pods and a policy by which to access them (sometimes this pattern is called a micro-service). The set of Pods targeted by a Service is usually determined by a selector

In this situation your service probably doesn't have proper endpoints, so my advice is to redeploy your nginx-ingress controller according to the official docs.

Depending on your needs you can expose your controller over:

Note:

Enabling this option exposes every system daemon to the NGINX Ingress controller on any network interface, including the host's loopback. Please evaluate the impact this may have on the security of your system carefully.

Once your ingress-controller will be working properly you can go through:

Note:

Caution: If you have more than one IngressClass marked as the default for your cluster, the admission controller prevents creating new Ingress objects that don't have an IngressClassName specified. You can resolve this by ensuring that at most 1 IngressClasses are marked as default in your cluster

0
votes

Since you are using NodePort type service to expose nginx ingress controller Kuberneretes will assign a port between 30000-32767 and you need to use that port to access.

But if you want to access it using port 80 on master node then you need to deploy nginx ingress controller via host Network

This can be achieved by enabling the hostNetwork option in the nginx ingress controller pods' spec by editing the existing deployment of nginx ingress controller or by changing the yaml and applying it.

template:
  spec:
    hostNetwork: true

Once you do this you should be to access micro services using curl <master-node-ip>/rest/endpoints/hello