使用Nginx入口控制器的minikube Kubernetes集群上没有入口地址

时间:2018-07-09 10:45:36

标签: kubernetes kubernetes-ingress

我有以下内容:

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: abcxyz
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: abcxyz
    http:
      paths:
      - path: /a/
        backend:
          serviceName: service-a
          servicePort: 80
      - path: /b/
        backend:
          serviceName: service-b
          servicePort: 80

kubectl describe ingress abcxyz的输出:

Name:             abcxyz
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host    Path  Backends
  ----    ----  --------
  abcxyz  
          /a/   service-a:80 (<none>)
          /b/   service-b:80 (<none>)
Annotations:
Events:
  Type    Reason  Age                From                      Message
  ----    ------  ----               ----                      -------
  Normal  CREATE  16m                nginx-ingress-controller  Ingress default/abcxyz
  Normal  UPDATE  12m (x2 over 15m)  nginx-ingress-controller  Ingress default/abcxyz

为什么地址为空?我已经使用helm install stable/nginx-ingress通过掌舵安装了“ nginx入口控制器”,并且所有的Pod相关事件似乎运行良好。

如何提供对入口的访问权限?

3 个答案:

答案 0 :(得分:2)

类型

minikube ip

检索主IP。例如:

bash-3.2$ minikube ip
192.168.1.100

提供有关kubernetes集群的信息的命令是:

bash-3.2$ kubectl cluster-info
Kubernetes master is running at https://192.168.1.100:8443
KubeDNS is running at https://192.168.1.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

您可以使用curl从主机上测试入口控制器:

bash-3.2$ curl http://192.168.1.100:80
default backend - 404

最后,添加一个主机条目,以便能够使用名称来引用集群IP地址

/etc/hosts中添加:

192.168.1.100   abcxyz

答案 1 :(得分:0)

我的解决方案是:

minikube addons enable ingress

答案 2 :(得分:0)

https://helm.nginx.com/stable 中似乎存在一个错误,使其无法绑定到 minikube 中的地址。

对我有用的解决方案是改用 https://kubernetes.github.io/ingress-nginx Kubernetes ingress 的 kubernetes 版本的安装说明在这里:https://kubernetes.github.io/ingress-nginx/deploy/,但这里是要点:

头盔

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

helm install ingress-nginx ingress-nginx/ingress-nginx

Minikube

minikube addons enable ingress

microk8s

microk8s enable ingress

还要注意,"bare metal" installation instructions 使用 NodePort。但大多数 IaaS 提供商都有自己分配 IP 的方式,因此他们对每个提供商都有特定的 instructions

# Source: ingress-nginx/templates/controller-service.yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
  labels:
    helm.sh/chart: ingress-nginx-3.33.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.47.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
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