下午有个集群要做升级验证, 同事把developer-center的namespaces下的应用都删除重建了,后来发现paas平台打不开,查询nginx日志,应该是nginx-ingress出了问题

首先查看ingress-nginx-cotroller日志:

 

可以修改deployment,使用  flag –v=XX来修改日志级别

  • --v=2 shows details using diff about the changes in the configuration in nginx
  • --v=3 shows details about the service, Ingress rule, endpoint changes and it dumps the nginx configuration in JSON format
  • --v=5 configures NGINX in debug mode

到api server的认证逻辑:

得确定下看是否是服务认证或kubeconfig导致的问题

ingress需要从 apiserver获得信息,是需要认证的,有两种认证方式:

  1. Service Account: This is recommended, because nothing has to be configured. The Ingress controller will use information provided by the system to communicate with the API server. See ‘Service Account’ section for details.
  2. Kubeconfig file: In some Kubernetes environments service accounts are not available. In this case a manual configuration is required. The Ingress controller binary can be started with the –kubeconfig flag. The value of the flag is a path to a file specifying how to connect to the API server. Using the –kubeconfig does not requires the flag –apiserver-host. The format of the file is identical to ~/.kube/config which is used by kubectl to connect to the API server. See ‘kubeconfig’ section for details.
  3. Using the flag –apiserver-host: Using this flag –apiserver-host=http://localhost:8080 it is possible to specify an unsecured API server or reach a remote kubernetes cluster using kubectl proxy. Please do not use this approach in production.

下面是从前端到后端完整的认证流程.

 

Service Account:

如果使用Service Account连接API server, ingress-controller需要存在/var/run/secrets/kubernetes.io/serviceaccount/token文件,来提供与API server认证所需要的secret token

可通过如下命令验证:

 

如下是我的验证过程:

If it is not working, there are two possible reasons:

  1. The contents of the tokens are invalid. Find the secret name with kubectl get secrets | grep service-account and delete it with kubectl delete secret <name>. It will automatically be recreated.
  2. You have a non-standard Kubernetes installation and the file containing the token may not be present. The API server will mount a volume containing this file, but only if the API server is configured to use the ServiceAccount admission controller. If you experience this error, verify that your API server is using the ServiceAccount admission controller. If you are configuring the API server by hand, you can set this with the --admission-control parameter.

    Note that you should use other admission controllers as well. Before configuring this option, you should read about admission controllers.

解决方式:重装ingress-nginx-controller

参考: https://kubernetes.github.io/ingress-nginx/troubleshooting/

Categories: KUBERNETES

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *