无法在openshift

时间:2018-02-25 22:31:00

标签: nginx openshift openshift-origin

我构建了自己的nginx图像。我可以用docker运行它并连接到端口8080

docker run -d -p 8080:8080  nginx_image
curl localhost:8080/index.php
Hello Michael

然后我推动此图像制作图像流并从中创建应用程序。

#tag and push stuff not displayed 
oc new-app --image-stream=nginx_image

按预期创建dc,svc,rc和pod:

oc get all -l app=nginximage
NAME                           REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfigs/nginximage   2          1         1         config,image(nginx_image:latest)

NAME                    READY     STATUS    RESTARTS   AGE
po/nginximage-2-ncv2l   1/1       Running   0          12m

NAME              DESIRED   CURRENT   READY     AGE
rc/nginximage-1   0         0         0         15m
rc/nginximage-2   1         1         1         12m

NAME             CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
svc/nginximage   172.30.169.72   <none>        8080/TCP   15m

但是我无法从群集中的节点连接到该服务

curl 172.30.169.72:8080
curl: (7) Failed connect to 172.30.169.72:8080; Connexion refusée

与工作的ruby应用程序进行比较后,我没有看到任何差异。现在我真的看不出如何解决这个问题。

修改1

按照Will Gordon的建议,我尝试在吊舱内卷曲,再次连接被拒绝。

oc rsh nginximage-2-ncv2l
# curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

仍然在pod内我试着看到哪个端口被打开

# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

none ......以及正在运行的进程

# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0   4492   648 ?        Ss   20:47   0:00 /bin/sh ./start.sh
root          5  0.0  0.7  56140 15068 ?        S    20:47   0:01 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
root          8  0.0  0.2 124960  5200 ?        S    20:47   0:00 nginx: master process /usr/sbin/nginx
root          9  0.0  1.0 211792 19040 ?        S    20:47   0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data     10  0.0  0.0 125296  1812 ?        S    20:47   0:00 nginx: worker process
www-data     11  0.0  0.2 211792  5072 ?        S    20:47   0:00 php-fpm: pool www
www-data     12  0.0  0.2 211792  5072 ?        S    20:47   0:00 php-fpm: pool www
root       2868  0.0  0.0   4492   648 ?        Ss   22:54   0:00 /bin/sh -c TERM="xterm" /bin/sh
root       2871  0.0  0.0   4492   648 ?        S    22:54   0:00 /bin/sh
root       2872  0.0  0.0  34412  1512 ?        R+   22:54   0:00 ps aux

Nginx在这里,但没有收听任何端口,很奇怪......

如果我与群集外的docker容器进行比较

docker exec -it  romantic_poitras bash
# curl localhost:8080/index.php
Hello Michael
# netstat -tulnp 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      8/nginx
tcp6       0      0 :::8080                 :::*                    LISTEN      8/nginx

Nginx正在收听预期的8080端口。为什么在openshift中部署nginx进程不会监听任何端口?它是否与我必须在ssc anyuid中添加serviceAccount这一事实有关?

修改2

Dockerfile

# download base image ubuntu 16.04
FROM ubuntu:16.04

# Update Software repository
RUN apt-get update

# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt-get install -y nginx php7.0-fpm supervisor && \
    rm -rf /var/lib/apt/lists/*


#Define the ENV variable
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf
ENV supervisor_conf /etc/supervisor/supervisord.conf


# Enable php-fpm on nginx virtualhost configuration
COPY default ${nginx_vhost}
RUN sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${php_conf} && \
    echo "\ndaemon off;" >> ${nginx_conf}

#Copy supervisor configuration
COPY supervisord.conf ${supervisor_conf}

RUN mkdir -p /run/php && \
    chown -R www-data:www-data /var/www/html && \
    chown -R www-data:www-data /run/php

# Volume configuration
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]
COPY index.php /var/www/html/index.php

# Configure Services and Port
COPY start.sh /start.sh
CMD ["./start.sh"]

EXPOSE 8080

nginx配置默认文件

server {
    listen 8080 default_server;
    listen [::]:8080 default_server;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

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

0 个答案:

没有答案