首页 > 解决方案 > OpenWhisk Ngnix Pod CrashLoopBackOff

问题描述

我对 OpenWhisk 非常陌生,并且在设置时遇到了一些困难。由于 Pod 中的错误,Ngnix Pod 正在 CrashLoopBackOff 中运行。

2018/07/02 16:14:27 [emerg] 1#1: host not found in resolver "kube-dns.kube-system" in /etc/nginx/nginx.conf:41
nginx: [emerg] host not found in resolver "kube-dns.kube-system" in /etc/nginx/nginx.conf:41

我无法跳入 Pod 本身,但我运行了一个 Docker 容器,该容器与 Pod 使用的镜像相同,并查看了 nginx.conf 内部:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

当我查看 conf.d 目录时,我发现了一个 default.conf 文件,其中 server_name 设置为 localhost:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

我相信这是导致问题的原因,并且 kube.dns 服务无法解析 localhost。

但是我不知道如何解决此问题或至少解决它。也许我可以在 Ngnix 部署中为 Pod 设置一个静态主机名,然后将该主机名输入到 ngnix 配置中?

有人可以为我提供解决方法甚至修复吗?

非常感谢。

标签: nginxkubernetescontainersopenwhisk

解决方案


kubeadm 从您当前运行的主机操作系统会话中获取并检查环境。

您可以通过执行以下命令检查是否已设置代理:

env | grep _proxy

在代理服务器配置为访问 Internet 服务的环境中,例如 Docker Hub 或 Oracle Container Registry,您可能需要执行几个配置步骤才能让 Kubernetes 安装并正确运行。

  • 确保集群中每个节点上的 Docker 引擎启动配置都配置为使用代理服务器。例如,在 /etc/systemd/system/docker.service.d/http-proxy.conf 中创建一个 systemd 服务插件文件,其内容如下:

    [Service]

    Environment="HTTP_PROXY=http://proxy.example.com:80/" Environment="HTTPS_PROXY=https://proxy.example.com:443/"

    http://proxy.example.com:80/替换为您的 HTTP 代理服务的 URL。如果您有 HTTPS 代理并且您也指定了它,请将https://proxy.example.com:443/替换为该服务的 URL 和端口。如果您对 Docker systemd 服务配置进行了更改,请运行以下命令:

    systemctl daemon-reload; systemctl restart docker

  • 您可能需要设置 http_proxy 或 https_proxy 环境变量,以便能够在集群中的任何节点上运行其他命令。例如:

    export http_proxy="http://proxy.example.com:80/"

    export https_proxy="https://proxy.example.com:443/"

  • 禁用 localhost 和集群中任何节点 IP 的代理配置:

    export no_proxy="127.0.0.1, 192.0.2.10, 192.0.2.11, 192.0.2.12"

这些步骤应该足以使部署正常运行。使用不需要在主机上进行配置且忽略内部网络请求的透明代理可以降低配置的复杂性并有助于避免意外行为。


推荐阅读