我还在学习k8s,但我有一个相当简单的设置,据我所知应该工作正常。
我打开了nginx-ingress:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
字符串
应用了入口服务:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.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
的字符串
后端服务和部署:
apiVersion: v1
kind: Service
metadata:
name: server-service
spec:
ports:
- port: 5000
protocol: TCP
selector:
app: server
type: ClusterIP
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: server
spec:
containers:
- name: server
image: jowz/server:v1
imagePullPolicy: Always
ports:
- containerPort: 5000
name: nodejs-port
selector:
matchLabels:
app: server
的字符串
但得到了503回应。就调试而言,我遇到的所有问题都是,通常会列出一个错别字或不正确的服务名称。我已经检查了所有这些,我已经查看了每个名称空间中每个服务的“describe”,查看了Selectors中列出的pod,所有都在运行,没有错误。为了更简单地读出数据,下面是kubectl get pods的输出--all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
ingress-nginx client-deployment-9ccf8cf87-7g6qr 1/1 Running 0 40h
ingress-nginx ingress-nginx-admission-create-tsp4n 0/1 Completed 0 44h
ingress-nginx ingress-nginx-admission-patch-q7spm 0/1 Completed 1 44h
ingress-nginx ingress-nginx-controller-86b55bb769-2bqs5 1/1 Running 0 44h
ingress-nginx mongodb 1/1 Running 0 41h
ingress-nginx server-deployment-df679664f-99nrq 1/1 Running 0 41h
kube-system event-exporter-gke-d4b7ff94-4st8l 2/2 Running 0 2d17h
kube-system fluentbit-gke-xlv7v 2/2 Running 0 2d17h
kube-system gke-metrics-agent-fhnmq 2/2 Running 0 2d17h
kube-system konnectivity-agent-697c66b96-bvfdw 1/1 Running 0 2d17h
kube-system konnectivity-agent-autoscaler-864fff96c4-n9tlp 1/1 Running 0 2d17h
kube-system kube-dns-autoscaler-758c4689b9-7gzx8 1/1 Running 0 2d17h
kube-system kube-dns-fc686db9b-hjl4d 4/4 Running 0 2d17h
kube-system kube-proxy-gke-octodemo-default-pool-20afc590-94qj 1/1 Running 0 2d17h
kube-system l7-default-backend-9db4bd868-zgx8s 1/1 Running 0 2d17h
kube-system metrics-server-6f6cdbf67d-m6hgv 1/1 Running 0 40h
kube-system metrics-server-v0.5.2-66bbcdbffc-bmzp6 2/2 Running 0 2d17h
kube-system pdcsi-node-st68b 2/2 Running 0 40h
型
我在GKE上托管了这个集群,在控制台或日志中也没有列出错误。我不知道还能怎么调试这个。
1条答案
按热度按时间e5njpo681#
检查服务是否正常:
kubectl get services
命令检查服务的状态,并确保它们具有IP地址和ClusterIP类型。kubectl get endpoints service-name
个kubectl port-forward <resource_type>/<resource_name> <local_port>:<remote_port>