Kubernetes ingress IP设置为docker0 ip

时间:2017-02-05 22:54:28

标签: kubernetes kubelet

我正在尝试在没有云提供商的裸机上使用kubernetes入口资源。

我创建了一个入口资源:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx
spec:
  rules:
  - host: foobar.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: echoheaders-x
          servicePort: 80
      - path: /
        backend:
          serviceName: frontend
          servicePort: 80

然而,当我查看入口时,我得到了这个IP:

[root@kubemaster]# kubectl get ing
NAME      HOSTS       ADDRESS      PORTS     AGE
nginx     foobar.com   172.17.0.1   80        12m

该IP地址似乎与我所有的kubelet节点上的docker0 IP地址一致。

有没有办法设置这个IP?我读过的所有教程似乎都让这个IP可以路由。

这是我的nginx-controller yaml:

---
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-controller
  labels:
    k8s-app: nginx-ingress-lb
spec:
  replicas: 1
  selector:
    k8s-app: nginx-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - image: gcr.io/google_containers/nginx-ingress-controller:0.8.3
        name: nginx-ingress-lb
        imagePullPolicy: Always
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        # use downward API
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        # we expose 18080 to access nginx stats in url /nginx-status
        # this is optional
        - containerPort: 18080
          hostPort: 18080
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
        - --nginx-configmap=$(POD_NAMESPACE)/nginx-ingress-controller

1 个答案:

答案 0 :(得分:1)

这里的问题是kubelet配置。默认情况下,kubelet会在0.0.0.0上收听,因为docker0是第一个可用的地址,所以它抓取了docker0的IP。

我在kubelet配置中添加了以下内容:

--address=<actualip> --node-ip=<actualip>

它注册正确。