设置Ingress(Kubernetes)

时间:2018-04-26 12:47:10

标签: nginx kubernetes google-cloud-platform kubernetes-helm

我想设置一个Ingress,它将流量路由到我的底层服务。不幸的是,我在部署ingress-controller-deployment.yaml时遇到错误,我不知道为什么......带有入口控制器的pod立即崩溃,出现错误消息" CrashLoopBackOff&#34 ;

根据我的理解,Ingress-Control必须部署在Pod中,并且可以通过ingress-svc访问此pod。 ingress-svc似乎有效,但Pod崩溃了。在入口控制器工作之后,我需要一个定义路由和所有内容的附加文件。但我没有看到继续使用可工作且可部署的入口控制器的重点。

Pod description:

    Name:           ingress-controller-7749c785f-x94ll
    Namespace:      ingress
    Node:           gke-cluster-1-default-pool-8484e77d-r4wp/10.128.0.2
    Start Time:     Thu, 26 Apr 2018 14:25:04 +0200
    Labels:         k8s-app=nginx-ingress-lb
                    pod-template-hash=330573419
    Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"ingress","name":"ingress-controller-7749c785f","uid":"d8ff0a6d-494c-11e8-a840
    -420...
    Status:         Running
    IP:             10.8.0.14
    Created By:     ReplicaSet/ingress-controller-7749c785f
    Controlled By:  ReplicaSet/ingress-controller-7749c785f
    Containers:
      nginx-ingress-controller:
        Container ID:  docker://5654c7dffc44510132cba303d66ee570280f2cec235e4d4fa6ef8ad543e0c91d
        Image:         quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0
        Image ID:      docker-pullable://quay.io/kubernetes-ingress-controller/nginx-ingress-controller@sha256:39cc6ce23e5bcdf8aa78bc28bbcfe0999e449bf99fe2e8d60984b417facc5cd4
        Ports:         80/TCP, 443/TCP
        Args:
          /nginx-ingress-controller
          --admin-backend-svc=$(POD_NAMESPACE)/admin-backend
        State:          Waiting
          Reason:       CrashLoopBackOff
        Last State:     Terminated
          Reason:       Error
          Exit Code:    2
          Started:      Thu, 26 Apr 2018 14:26:57 +0200
          Finished:     Thu, 26 Apr 2018 14:26:57 +0200
        Ready:          False
        Restart Count:  4
        Liveness:       http-get http://:10254/healthz delay=10s timeout=5s period=10s #success=1 #failure=3
        Environment:
          POD_NAME:       ingress-controller-7749c785f-x94ll (v1:metadata.name)
          POD_NAMESPACE:  ingress (v1:metadata.namespace)
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from default-token-plbss (ro)
    Conditions:
      Type           Status
      Initialized    True
      Ready          False
      PodScheduled   True
    Volumes:
      default-token-plbss:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  default-token-plbss
        Optional:    false
    QoS Class:       BestEffort
    Node-Selectors:  <none>
    Tolerations: node.alpha.kubernetes.io/notReady:NoExecute for 300s
node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Ingress-controller-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ingress-controller
spec:
  replicas: 1
  revisionHistoryLimit: 3
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
    spec:
      containers:
        - args:
            - /nginx-ingress-controller
            - "--admin-backend-svc=$(POD_NAMESPACE)/admin-backend"
          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.9.0"
          imagePullPolicy: Always
          livenessProbe:
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            timeoutSeconds: 5
          name: nginx-ingress-controller
          ports:
            - containerPort: 80
              name: http
              protocol: TCP
            - containerPort: 443
              name: https
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: ingress-svc
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https
  selector:
    k8s-app: nginx-ingress-lb

1 个答案:

答案 0 :(得分:2)

问题在于args。我的一个人的争论是

      args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
        - --configmap=$(POD_NAMESPACE)/nginx-configuration
        - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
        - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
        - --publish-service=$(POD_NAMESPACE)/ingress-nginx
        - --annotations-prefix=nginx.ingress.kubernetes.io

我还为配置,tcp和udp创建了配置映射。