带有Kubernetes的Ingress

带有Kubernetes的Ingress

本文介绍了带有Kubernetes的Ingress-Nginx没有获得IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kubernetes的新手,正在尝试让Ingress-Nginx在我的本地k8s集群上工作.

I am new to Kubernetes and am attempting to get Ingress-Nginx to work on my local k8s cluster.

我已安装并运行它:

$ kubectl get pods --namespace=ingress-nginx
  NAME                                       READY   STATUS    RESTARTS   AGE
  nginx-ingress-controller-76f97b74b-bbb6h   1/1     Running   0          13h

然后,我创建了两个nginx服务(希望测试基于名称的路由):

Then I created two nginx services (wanted to test name-based routing):

$ kubectl get svc
  NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
    kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        20h
    nginx        NodePort    10.102.188.253   <none>        80:32025/TCP   36m
    nginx2       NodePort    10.109.43.89     <none>        80:32458/TCP   35m

然后我创建了入口:

$ kubectl get ingress -o yaml
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    creationTimestamp: 2018-10-25T12:27:44Z
    generation: 1
    name: test
    namespace: default
    resourceVersion: "98114"
    selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/test
    uid: 5fbc2e9e-d851-11e8-995f-2ae1e5e17bac
  spec:
    rules:
    - host: test-ingress.chbresser.com
      http:
        paths:
        - backend:
            serviceName: nginx
            servicePort: 80
    - host: test-ingress2.chbresser.com
      http:
        paths:
        - backend:
            serviceName: nginx2
            servicePort: 80
  status:
    loadBalancer: {}
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

根据我的理解,这是我应该做的,但没有获得IP地址:

From my understanding that is all I was supposed to do, but its not getting an IP address:

$ kubectl get ingress
  NAME   HOSTS                                                    ADDRESS   PORTS   AGE
    test   test-ingress.chbresser.com,test-ingress2.chbresser.com             80      33m

我错过了哪一步?为什么我没有IP?

What step did I miss? Why am I not getting an IP?

kubectl logs nginx-ingress-controller-76f97b74b-bbb6h --namespace=ingress-nginx:

W1025 05:44:10.003587       9 queue.go:130] requeuing &ObjectMeta{Name:sync status,GenerateName:,Namespace:,SelfLink:,UID:,ResourceVersion:,Generation:0,CreationTimestamp:0001-01-01 00:00:00 +0000 UTC,DeletionTimestamp:<nil>,DeletionGracePeriodSeconds:nil,Labels:map[string]string{},Annotations:map[string]string{},OwnerReferences:[],Finalizers:[],ClusterName:,Initializers:nil,}, err services "ingress-nginx" not found

推荐答案

我使用Bare-metal并通过--report-node-internal-ip-address=true获取IP地址在ingress-controller中标记.

I use Bare-metal and get IP address by using --report-node-internal-ip-address=trueflag in ingress-controller.

这是我的ingress-controller yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
spec:
  replicas: 1
  revisionHistoryLimit: 3
  template:
    metadata:
      labels:
        k8s-app: ingress-nginx
    spec:
      containers:
        - args:
            - /nginx-ingress-controller
            - "--default-backend-service=default/my-app"
            - "--report-node-internal-ip-address=true"
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          image: "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.15.0"
          name: nginx-ingress-controller
          ports:
            - containerPort: 80
              hostPort: 80
              name: http
              protocol: TCP

我的ingress yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: my-app.example.com
    http:
     paths:
     - path: /
       backend:
        serviceName: my-app
        servicePort: 80

和结果:

$ kubectl get ing
NAME     HOSTS   ADDRESS        PORTS   AGE
my-app   *       192.168.1.78   80      40h

$ kubectl get svc
NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes        ClusterIP   10.96.0.1        <none>        443/TCP          8d
my-app            ClusterIP   10.110.152.216   <none>        80/TCP,443/TCP   8d

$ kubectl get po
NAME                                        READY   STATUS    RESTARTS   AGE
my-app-rc-d7lw9                             1/1     Running   0          8d
my-app-rc-spvjb                             1/1     Running   0          8d
my-app-rc-tvkrw                             1/1     Running   0          8d
nginx-ingress-controller-6c6c899467-d9sg6   1/1     Running   0          16m

有关更多详细信息,请参见此问题.

for more detail , see this issues.

这篇关于带有Kubernetes的Ingress-Nginx没有获得IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:08