我是k8s的新手,正在尝试在GKE上设置一个集群。我有它的工作密切,只是服务和nginx内置到前端图像,但路由是不正确的工作,所以在网上看,它明确我应该使用一个入口。我一直在尝试设置nginx入口,但一直收到404响应,我不知道我做错了什么。
我把入口从这里拉出来:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
字符串
并将控制器yaml设置为:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
nginx.ingress.kubernetes.io/user-regex: "true"
nginx.ingress.kuberenetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin"
spec:
rules:
- http:
paths:
- path: /?(.*)
pathType: Prefix
backend:
service:
name: client-service
port:
number: 3000
- path: /api/?(.*)
pathType: Prefix
backend:
service:
name: server-service
port:
number: 5000
ingressClassName: nginx
型
客户服务:
apiVersion: v1
kind: Service
metadata:
name: client-service
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-port
selector:
app: client
type: ClusterIP
型
客户端部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: jowz/client:v4.2
ports:
- containerPort: 3000
name: http-port
selector:
matchLabels:
app: client
型
我没有错误,图像拉问题,或任何显示在终端或在GKE控制台。
pod:
NAMESPACE NAME READY STATUS RESTARTS AGE
default client-deployment-9ccf8cf87-27pvv 1/1 Running 0 87m
default mongodb 1/1 Running 0 21h
default server-deployment-df679664f-q9fjw 1/1 Running 0 87m
ingress-nginx ingress-nginx-admission-create-tsp4n 0/1 Completed 0 9m23s
ingress-nginx ingress-nginx-admission-patch-q7spm 0/1 Completed 1 9m23s
ingress-nginx ingress-nginx-controller-86b55bb769-2bqs5 1/1 Running 0 9m24s
kube-system event-exporter-gke-d4b7ff94-4st8l 2/2 Running 0 21h
kube-system fluentbit-gke-xlv7v 2/2 Running 0 21h
kube-system gke-metrics-agent-fhnmq 2/2 Running 0 21h
kube-system konnectivity-agent-697c66b96-bvfdw 1/1 Running 0 21h
kube-system konnectivity-agent-autoscaler-864fff96c4-n9tlp 1/1 Running 0 21h
kube-system kube-dns-autoscaler-758c4689b9-7gzx8 1/1 Running 0 21h
kube-system kube-dns-fc686db9b-hjl4d 4/4 Running 0 21h
kube-system kube-proxy-gke-octodemo-default-pool-20afc590-94qj 1/1 Running 0 21h
kube-system l7-default-backend-9db4bd868-zgx8s 1/1 Running 0 21h
kube-system metrics-server-v0.5.2-66bbcdbffc-bmzp6 2/2 Running 0 21h
kube-system pdcsi-node-fqzzl 2/2 Running 0 21h
型
服务:
default client-service ClusterIP 10.92.6.30 <none> 3000/TCP 88m
default kubernetes ClusterIP 10.92.0.1 <none> 443/TCP 21h
default mongodb-service ClusterIP 10.92.4.232 <none> 27017/TCP 21h
default server-service ClusterIP 10.92.15.190 <none> 5000/TCP 88m
ingress-nginx ingress-nginx-controller LoadBalancer 10.92.2.242 35.235.98.121 80:30275/TCP,443:30487/TCP 10m
ingress-nginx ingress-nginx-controller-admission ClusterIP 10.92.13.144 <none> 443/TCP 10m
kube-system default-http-backend NodePort 10.92.14.152 <none> 80:30200/TCP 21h
kube-system kube-dns ClusterIP 10.92.0.10 <none> 53/UDP,53/TCP 21h
kube-system metrics-server ClusterIP 10.92.11.249 <none> 443/TCP 21h
型
Curling会得到与浏览器相同的响应:
* Trying 35.235.98.121:80...
* Connected to 35.235.98.121 (35.235.98.121) port 80 (#0)
> GET / HTTP/1.1
> Host: 35.235.98.121
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Date: Tue, 18 Jul 2023 21:05:23 GMT
< Content-Type: text/html
< Content-Length: 146
< Connection: keep-alive
<
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host 35.235.98.121 left intact
型
但是ping返回find:
--- 35.235.98.121 ping statistics ---
43 packets transmitted, 43 received, 0% packet loss, time 42063ms
rtt min/avg/max/mdev = 21.119/36.551/206.584/33.645 ms
型
如果有人能看出我哪里做错了,请告诉我。一直在绕圈子想把我的脑袋弄明白
1条答案
按热度按时间jgwigjjp1#
我认为这里的主要问题是您拼错了Ingress资源上的一些注解。
1.你写了
user
,你的意思是use
。而不是:字符串
您需要:
型
1.您将
kubernetes
拼写为kuberenetes
。而不是:型
您需要:
型
有了这两个变化,事情似乎按预期进行。你可以看到我的完整测试here。