我在google cloud上有一个集群设置,其中一个部署是在nginx上的containerized Angular应用程序:
apiVersion: apps/v1
kind: Deployment
metadata:
name: product-adviser-front-deployment
labels:
app: angular-front
version: v1
spec:
replicas: 1
selector:
matchLabels:
name: product-adviser-front-deployment
template:
metadata:
labels:
name: product-adviser-front-deployment
spec:
containers:
- name: product-adviser-front-app
image: aurrix/seb:product-adviser-front
imagePullPolicy: Always
ports:
- containerPort: 80
env:
- name: API_URL
value: http://back:8080/
readinessProbe:
initialDelaySeconds: 30
httpGet:
path: /healthz
port: 80
livenessProbe:
initialDelaySeconds: 30
httpGet:
path: /healthz
port: 80
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: front
spec:
selector:
name: product-adviser-front-deployment
ports:
- port: 80
type: NodePort
Nginx配置:
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
#Allow CORS
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
log_format gzip '[$time_local] ' '"$request" $status $bytes_sent';
index index.html;
include /etc/nginx/mime.types;
default_type application/javascript;
access_log /dev/stdout;
charset utf-8;
sendfile on;
keepalive_timeout 65;
#include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name localhost;
access_log /dev/stdout;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
try_files $uri $uri/ =404;
}
location /healthz {
return 200 'no content';
}
}
# Compression
#include /etc/nginx/gzip.conf;
}
入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: main-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: front
servicePort: 80
然而,每当我访问外部IP地址时,angular应用程序使用index.html响应时都无法加载资源。
我非常确定这与入口配置有关,但我想我已经精疲力竭地试图弄清楚这一点。
我在这里做错了什么?
顺便说一句,我已经在集群中安装了ingress nginx,它似乎工作得很好。基本href存在于index.html中。docker镜像在本地工作得很好。
发布于 2020-04-08 15:41:32
配置按原样工作。似乎入口需要以删除并重新申请的方式强制重新启动。
发布于 2020-04-08 02:44:53
您如何访问它以及从哪里访问它。您能粘贴curl -vvv外部IP/路径的结果吗?
另外,您可以从pod中卷曲相同的服务卷曲-vvv front.svc.cluster.local:80吗?
我也不确定环境变量API URL,这个值看起来很奇怪。
https://stackoverflow.com/questions/61086914
复制相似问题