我已经创建了 ubuntu docker 镜像,其中配置了 Nginx、PHP 和 php-fpm。当我在 Docker 实例上运行它时它工作正常。
但是当我在 kubernetes 中运行相同的图像时,php-fpm 进程会收到 SIGKILL (9) 信号,并且我们会收到 502 网关错误。
我猜是 kubernetes 将 SIGKILL 信号发送到 kubernetes pod。我没有在 kubernetes 模板中使用任何就绪性和活力探测。
感谢任何帮助。提前致谢。
在下面找到 docker 文件和 php-fpm 日志以获取详细信息,
Dockerfile
FROM ubuntu
#install utilities tools
RUN apt-get update \
&& apt-get install -y vim unzip curl python-software-properties software-properties-common locales supervisor
# Update software list, install php-nginx & clear cache
RUN locale-gen en_US.UTF-8 && \
export LANG=en_US.UTF-8 && \
add-apt-repository -y ppa:ondrej/php && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --force-yes nginx \
php5.6 php5.6-zip php5.6-fpm php5.6-cli php5.6-mysql php5.6-mcrypt php5.6-xml\
php5.6-curl php5.6-gd && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
# Configure nginx
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN sed -i "s/sendfile on/sendfile off/" /etc/nginx/nginx.conf
RUN mkdir -p /var/www/html
# Configure PHP
RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/5.6/fpm/php.ini && \
sed -i -e "s/;date.timezone =.*/date.timezone = America\/Argentina\/Buenos_Aires/" /etc/php/5.6/fpm/php.ini && \
sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 100M/g" /etc/php/5.6/fpm/php.ini && \
sed -i -e "s/post_max_size\s*=\s*8M/post_max_size = 100M/g" /etc/php/5.6/fpm/php.ini && \
sed -i -e "s/variables_order = \"GPCS\"/variables_order = \"EGPCS\"/g" /etc/php/5.6/fpm/php.ini
##Updated for PHP 5.6
RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php/5.6/fpm/php-fpm.conf && \
sed -i -e "s/pid =.*/pid = \/var\/run\/php-fpm.pid/" /etc/php/5.6/fpm/php-fpm.conf && \
sed -i -e "s/listen =.*sock/listen = 127.0.0.1:9000/" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/;clear_env = no/clear_env = no/" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/pm.max_children = 5/pm.max_children = 4/g" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/pm.start_servers = 2/pm.start_servers = 3/g" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/pm.min_spare_servers = 1/pm.min_spare_servers = 2/g" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/pm.max_spare_servers = 3/pm.max_spare_servers = 4/g" /etc/php/5.6/fpm/pool.d/www.conf && \
sed -i -e "s/;pm.max_requests = 500/pm.max_requests = 200/g" /etc/php/5.6/fpm/pool.d/www.conf
RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/5.6/cli/php.ini && \
sed -i -e "s/;date.timezone =.*/date.timezone = America\/Argentina\/Buenos_Aires/" /etc/php/5.6/cli/php.ini && \
sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 100M/g" /etc/php/5.6/cli/php.ini && \
sed -i -e "s/post_max_size\s*=\s*8M/post_max_size = 100M/g" /etc/php/5.6/cli/php.ini && \
sed -i -e "s/variables_order = \"GPCS\"/variables_order = \"EGPCS\"/g" /etc/php/5.6/cli/php.ini
COPY opsconfig/default_server_config /etc/nginx/sites-available/default
COPY opsconfig/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
RUN phpenmod -v 5.6 mcrypt && \
phpenmod -v 5.6 xdebug && \
phpenmod -v 5.6 zip
#install composer
RUN curl -O https://getcomposer.org/composer.phar && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
# Workdir
WORKDIR /var/www/html
COPY src/ /var/www/html/
RUN chown -R www-data:www-data /var/www/html
CMD ["/usr/bin/supervisord"]
主管.conf
[supervisord]
nodaemon=true
[program:php-fpm]
command=/usr/sbin/php-fpm5.6 --nodaemonize
[program:nginx]
command=/usr/sbin/nginx
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
php-fpm.log
[10-Oct-2017 16:52:02] NOTICE: fpm is running, pid 56
[10-Oct-2017 16:52:02] NOTICE: ready to handle connections
[10-Oct-2017 16:52:02] NOTICE: systemd monitor interval set to 10000ms
[10-Oct-2017 16:52:30] WARNING: [pool www] child 57 exited on signal 9 (SIGKILL) after 28.399445 seconds from start
[10-Oct-2017 16:52:30] NOTICE: [pool www] child 61 started
[10-Oct-2017 16:52:38] WARNING: [pool www] child 59 exited on signal 9 (SIGKILL) after 36.796172 seconds from start
[10-Oct-2017 16:52:38] NOTICE: [pool www] child 62 started
[10-Oct-2017 16:53:15] WARNING: [pool www] child 58 exited on signal 9 (SIGKILL) after 73.299127 seconds from start
[10-Oct-2017 16:53:15] NOTICE: [pool www] child 63 started
[10-Oct-2017 17:45:02] WARNING: [pool www] child 62 exited on signal 9 (SIGKILL) after 3143.801344 seconds from start
[10-Oct-2017 17:45:02] NOTICE: [pool www] child 64 started
Nginx 日志
2017/10/10 16:53:15 [error] 11#11: *162 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.244.2.49, server: _, request: "GET /admin/index.php?route=common/dashboard&token=V4iXjKHenn2ZOIldfn4pmIHcTIHiFoxk HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "shop9.homesourcesystems.net", referrer: "https://domain_name/admin/"
2017/10/10 17:45:02 [error] 11#11: *166 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.244.2.49, server: _, request: "GET /admin/index.php?route=common/dashboard&token=sFiMAItAgX22BarBfcNNVuyin50ZauIa HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "shop9.homesourcesystems.net", referrer: "https://domain_name/admin/"
Pod 定义
Name: bumptious-beetle-3107682338-qlvcf
Namespace: testns
Node: k8s-agent-1/10.240.0.4
Start Time: Wed, 11 Oct 2017 09:26:21 +0000
Labels: app=testapp
pod-template-hash=3107682338
release=bumptious-beetle
Annotations: checksum/config=466a2fbe40164c0f5a10a06e26417c92a47422720e96c4fb51562eb8388d282f
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"testns","name":"bumptious-beetle-3107682338","uid":"3e2745b7-ae66...
Status: Running
IP: 10.244.0.205
Controllers: ReplicaSet/bumptious-beetle-3107682338
Containers:
hstestns:
Container ID: docker://31477927d3d0ac1b3f2fe662601d1d65d2a6d1fb442e580f9c1836e921a85f75
Image: phpnginx:1.9
Image ID: docker-pullable://phpnginx@sha256:7dfb96e283f0802e72249aeb252d3e6290dec00591c442da80bfa4727cef7ca5
Port: 80/TCP
State: Running
Started: Wed, 11 Oct 2017 09:26:42 +0000
Ready: True
Restart Count: 0
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 10m
memory: 40Mi
Environment Variables from:
bumptious-beetle ConfigMap Optional: false
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-ptkqw (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-ptkqw:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-ptkqw
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
13m 13m 1 default-scheduler Normal Scheduled Successfully assigned bumptious-beetle-3107682338-qlvcf to k8s-agent-1
13m 13m 1 kubelet, k8s-agent-1 spec.containers{hsecommerce} Normal Pulling pulling image "phpnginx:1.9"
13m 13m 1 kubelet, k8s-agent-1 spec.containers{hsecommerce} Normal Pulled Successfully pulled image "phpnginx:1.9"
13m 13m 1 kubelet, k8s-agent-1 spec.containers{hsecommerce} Normal Created Created container with id 31477927d3d0ac1b3f2fe662601d1d65d2a6d1fb442e580f9c1836e921a85f75
13m 13m 1 kubelet, k8s-agent-1 spec.containers{hsecommerce} Normal Started Started container with id 31477927d3d0ac1b3f2fe662601d1d65d2a6d1fb442e580f9c1836e921a85f75
问候, 拉胡尔