Среда: RubyOnRails + Puma + nginx + Docker + Kubernetes
Я сделал развертывание в k8s. Я сделал один стручок, включая 3 контейнера.
Один для ruby на рельсах, другой для веб-упаковщика и другой для nginx.
Но проблема в том, что когда я проверяю localhost в моем nginx контейнере с помощью curl http://localhost
, он возвращает:
502 сбойный шлюз
Нет проблем с результатом из curl http://localhost:3000
.
Я думаю, что может быть что-то не так в настройках nginx.
Пожалуйста, дайте мне знать, в чем проблема.
Kubernetes yaml
apiVersion: v1
kind: Service
metadata:
namespace: line-manager
name: web
labels:
app: web
spec:
selector:
app: web
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: line-manager
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: khjoo19/nginx:v2
imagePullPolicy: Always
command: ["/usr/sbin/nginx", "-g", "daemon off;", "-c", "/etc/nginx/nginx.conf"]
ports:
- containerPort: 80
volumeMounts:
- name: mysql-pv
mountPath: /var/lib/mysql
- name: webpacker
image: khjoo19/fullout-line:v2
imagePullPolicy: Always
command: ["bundle", "exec", "bin/webpack-dev-server"]
ports:
- containerPort: 8080
- name: web
image: khjoo19/fullout-line:v2
imagePullPolicy: Always
command: ["bundle", "exec", "puma", "-C", "config/puma.rb"]
env:
- name: MYSQL_DATABASE
value: lineManage_db
- name: MYSQL_USER
value: root
- name: MYSQL_HOST
value: mysql
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3000
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 30
volumeMounts:
- name: mysql-pv
mountPath: /var/lib/mysql
volumes:
- name: mysql-pv
persistentVolumeClaim:
claimName: mysql-pvc
nginx .conf
upstream line_manager {
server unix:///line_manager/tmp/sockets/puma.sock;
}
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /line_manager/public;
client_max_body_size 100m;
error_page 404 /404.html;
error_page 505 502 503 504 /500.html;
try_files $uri/index.html $uri @line_manager;
keepalive_timeout 30;
location @line_manager {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://line_manager;
}
}
puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
app_root = File.expand_path("../..", __FILE__)
bind "unix://#{app_root}/tmp/sockets/puma.sock"
stdout_redirect "#{app_root}/log/puma.stdout.log", "#{app_root}/log/puma.stderr.log", true