Nginx入口控制器无法运行

时间:2019-02-14 09:02:13

标签: docker kubernetes kubernetes-ingress nginx-ingress

我正在尝试在没有负载平衡器和云提供程序的情况下在自己的服务器中部署Nginx-ingress控制器。我执行了以下步骤:

apiVersion: v1
kind: Namespace
metadata:
  name: ingress-nginx

然后,我为serviceAccount创建了一个名为nginx-ingress的群集角色。
我的nginx-controller-service.yaml

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: NodePort
  selector:
    app: ingress-nginx
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https
  externalIPs:
    - my-external-node-ip

还有nginx-ingress-controller.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ingress-nginx
  template:
    metadata:
      labels:
        app: ingress-nginx
      annotations:
        prometheus.io/port: '10254'
        prometheus.io/scrape: 'true'
    spec:
      serviceAccountName: nginx-ingress
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0-beta.17
          args:
            - /nginx-ingress-controller
            - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
          - name: http
            containerPort: 80
          - name: https
            containerPort: 443
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1

但是,当我获得部署状态时,它显示给我:

NAMESPACE       NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
ingress-nginx   deployment.apps/default-http-backend       1/1     1            1           17m
ingress-nginx   deployment.apps/nginx-ingress-controller   0/1     0            0           17m

控制器不可用/未运行。

这里出了什么问题,如何获取失败部署的日志?

2 个答案:

答案 0 :(得分:1)

该问题是由于缺少服务帐户引起的。

58m Warning FailedCreate ReplicaSet Error creating: pods "nginx-ingress-controller-5b7f66f95f-" is forbidden: error looking up service account ingress-nginx/nginx-ingress: serviceaccount "nginx-ingress" not found

使用以下命令可以创建SA

kubectl create serviceaccount my-service-account

进一步了解k8s-service-account

答案 1 :(得分:-1)

从服务清单中删除以下条目

externalTrafficPolicy: Local
  externalIPs:
    - my-external-node-ip