简体   繁体   English

Kubernetes Ingress 无法获取服务的集群 IP

[英]Kubernetes Ingress cannot fetch cluster ip of service

I setup a kubernetes single node master plane with calico and haproxy.我用 calico 和 haproxy 设置了一个 kubernetes 单节点主平面。 Now whenever I am going to create an Ingress, the address remains empty and the server returns a 503 error.现在每当我要创建一个 Ingress 时,地址保持为空并且服务器返回 503 错误。

The following shows my kubernetes deployments.下面显示了我的 kubernetes 部署。

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.这是我从 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.我希望入口将接收服务的集群 ip 并侦听给定的主机 uri 并提供除给定 503 错误之外的其他信息。

// Edit: Its a standalone node, not a desktop version or minikube installation! // 编辑:它是一个独立节点,不是桌面版本或 minikube 安装!

这个镜像的容器端口是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. 因此,首先将服务类型更改为NodePort,然后等待大约2或3分钟,直到出现Ingress的IP地址。

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 : 现在,如果我输入$ 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 . 如果您想了解有关Ingress的更多信息,请参阅分步教程 I hope it will helps you. 希望对您有帮助。

The service default type is ClusterIP, but it is meant only for cluster-internal communication.服务默认类型是 ClusterIP,但它仅用于集群内部通信。 For external traffic you should switch to a NodePort type.对于外部流量,您应该切换到 NodePort 类型。 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).如果我没记错的话,nginx alb 控制器允许使用 ClusterIP(或 LoadBalancer)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有集群 ip 服务和默认 nginx 的 kubernetes 入口控制器无法按预期工作 - kubernetes ingress controller with cluster ip service and default nginx not working as expected 通过kubernetes单节点集群创建服务不会给我任何&#39;ingress&#39;外部IP,但是Google容器引擎可以(?) - creating a service via kubernetes single node cluster gives me no 'ingress' external IP, but google container engine does (?) Kubernetes(minikube) + React 前端 + .netcore api + 集群 IP 服务 + ingress + net::ERR_NAME_NOT_RESOLVED - Kubernetes(minikube) + React Frontend + .netcore api + Cluster IP service + ingress + net::ERR_NAME_NOT_RESOLVED 使用入口在远程Kubernetes集群中的访问服务 - Access service in remote Kubernetes cluster using ingress kubernetes 负载均衡器服务 - 无法设置入口 ip - kubernetes loadbalancer service - unable to set ingress ip Kubernetes入口服务更新IP - Kubernetes Ingress-Service update IP kubernetes配置入口,ingress_nginx服务外部IP待处理 - kubernetes configuration Ingress,ingress_nginx service external IP pending Kubernetes 中的 metalLB 与入口与(节点端口或集群 ip) - metalLB vs ingress vs (nodeport or cluster ip) in kubernetes Kubernetes nginx 入口找不到后端服务 - Kubernetes nginx ingress cannot find backend service Nginx Kube.netes 集群上的入口 - Nginx Ingress on Kubernetes Cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM