简体   繁体   中英

Kubernetes Ingress cannot fetch cluster ip of service

I setup a kubernetes single node master plane with calico and haproxy. Now whenever I am going to create an Ingress, the address remains empty and the server returns a 503 error.

The following shows my kubernetes deployments.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: wordpress
          ports:
            - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: web-ingress
spec:
  rules:
    - host: wordpress.example.org
      http:
        paths:
          - path: /
            backend:
              serviceName: nginx-service
              servicePort: 8080

This is my output from the kubernetes cl.

NAME                             HOSTS                   ADDRESS   PORTS   AGE
ingress.extensions/web-ingress   wordpress.example.org             80      35s

NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP    10h
service/nginx-service   ClusterIP   10.97.189.233   <none>        8080/TCP   35s

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/nginx-deployment   1/1     1            1           35s

NAME                                    READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-7798df5dd5-gnwf2   1/1     Running   0          35s

NAME                      ENDPOINTS              AGE
endpoints/kubernetes      164.68.103.199:6443    10h
endpoints/nginx-service   192.168.104.150:8080   36s
Pascals-MBP-c8a4:api-gateway pascal$

I expect that the ingress will receive the cluster ip of the service and is listening on the given host uri and serving another information than the given 503 errors.

// Edit: Its a standalone node, not a desktop version or minikube installation!

这个镜像的容器端口是80,我暴露的是8080。

I have reproduced your problem and make a few changes, now it works fine. So firstly change the type of your service to NodePort, and wait like 2 or 3 minutes for IP address of the Ingress appeared.

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

Now, if I type $ kubectl get ingress :

NAME          HOSTS                   ADDRESS      PORTS   AGE
web-ingress   wordpress.example.org   34.98.73.0   80      66s

If you would like to read more about Ingress, refer to step-by-step tutorial . I hope it will helps you.

The service default type is ClusterIP, but it is meant only for cluster-internal communication. For external traffic you should switch to a NodePort type. For example:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP
      name: http
  selector:
    run: nginx

If I am not mistaken nginx alb controller allows using ClusterIP (or LoadBalancer).

More info here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM