我有一个网站,最近我写了一个使用kubernetes的部署。使用minikube将其部署到我的本地计算机上并使用- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
进行查看时,一切正常。但是,在GKE上部署并通过Ingress公开后,图像不会加载。将鼠标悬停在Insepct Element中的图像路径上时会显示“无法加载图像”。
我尝试过更改图像的路径,但这并不能解决问题。
minikube service srv-website
<img src="./Images/A.png" class="img">
<img src="Images/A.png" class="img">
前两个在本地工作,第三个没有绝对容器路径。即使它们都运行相同的映像,它们都不能在GKE上工作。
这是我的部署:
<img src="/usr/share/nginx/html/Images/A.png" class="img">
我的入口:
apiVersion: v1
kind: ConfigMap
metadata:
name: cfg-website
data:
custom.nginx.conf: |
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}
error_page 401 /401.html;
location = /401.html {
root /usr/share/nginx/html;
internal;
}
# gzip compression
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
# gzip compression
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep-website
labels:
app: website
spec:
selector:
matchLabels:
app: website
template:
metadata:
labels:
app: website
spec:
volumes:
- name: nginx-conf
configMap:
name: cfg-website
containers:
- name: cnt-website
image: link/to/registry
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx/conf.d
readOnly: true
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: srv-website
labels:
app: website
spec:
type: NodePort
selector:
app: website
ports:
- port: 8080
targetPort: 80
答案 0 :(得分:0)
问题不是我网站的图像路径,而是入口。入口仅将路径“ /”映射到我的网站,这意味着图像链接无效。通过将入口路径更改为“ / *”,它已得到修复,因为它允许网站上存在“ /”以外的路径。
新入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: website-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: website-ingress
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: srv-website
servicePort: 8080