nginx-ingress-controller:初始化与 Kubernetes apiserver 的连接时出错

nginx-ingress-controller: Error while initializing connection to Kubernetes apiserver

nginx-ingress-controller 错误。它在初始化与 kubernetes apiserver 的连接时出错。集群是否存在问题,无法理解此问题。我想在集群外公开我的服务。下面是带有错误的 docker 日志和我的 nginx-ingress-controller.yml

docker 日志

Creating API client for https://10.96.0.1:443
F1128 06:30:25.376076       7 launch.go:330] Error while initializing connection to 
Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has 
invalid apiserver certificates or service accounts configuration). Reason: Get  
https://10.96.0.1:443/version: dial tcp 10.96.0.1:443: i/o timeout

nginx-controller.yml

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


--- 
kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
labels:
  app: ingress-nginx
spec:
  externalTrafficPolicy: Local
type: LoadBalancer
selector:
app: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
- name: https
port: 443
targetPort: https


---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-ingress-controller
namespace: default
spec:
replicas: 1
#  selector:
#    matchLabels:
#      app: ingress-nginx
template:
metadata:
  labels:
    app: ingress-nginx
  annotations:
    prometheus.io/port: '10254'
    prometheus.io/scrape: 'true'
spec:
  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)/nginx-default-backend-external

        - --logtostderr
        - --configmap=$(POD_NAMESPACE)/nginx-ingress-config
        - --default-ssl-certificate=$(POD_NAMESPACE)/default-tls
      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

可能是什么原因

根据评论发布为 Community Wiki,以提高知名度。

问题的根本原因是 不是 nginx-controller 设置而是 Kubernetes Cluster Configuration.

1.使用错误 cidr.

原发帖人使用与主持人相同的 --pod-network-cidr 值。在 documentation.

中有描述

Also, beware, that your Pod network must not overlap with any of the host networks as this can cause issues. If you find a collision between your network plugin’s preferred Pod network and some of your host networks, you should think of a suitable CIDR replacement and use that during kubeadm init with --pod-network-cidr and as a replacement in your network plugin’s YAML.

2。 CoreDNS崩溃。

原始海报使用 kubectl -n kube-system edit configmap coredns 更改了 ConfigMap,其中包含有关 CoreDNS 配置的信息(注释循环)。后来 OP 安装了 CNI - Flannel 并重新启动 CoreDNS pods 以接收来自 ConfigMap 的新配置。

之后 Nginx-controller 配置 YAML 工作正常。