express-集群-ip-服务.yaml
apiVersion: v1
kind: Service
metadata:
name: express-cluster-ip-service
spec:
type: ClusterIP
selector:
component: server
ports:
- port: 5000
targetPort: 5000
express-部署.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: express-deployment
spec:
replicas: 3
selector:
matchLabels:
component: server
template:
metadata:
labels:
component: server
spec:
containers:
- name: express
image: simonjames/react-node-docker-kubernetes-app-express
ports:
- containerPort: 5000
env:
- name: REDIS_HOST
value: redis-cluster-ip-service
- name: REDIS_PORT
value: '6379'
- name: PGUSER
value: postgres
- name: PGHOST
value: postgres-cluster-ip-service
- name: PGPORT
value: '5432'
- name: PGDATABASE
value: postgres
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: pgpassword
key: PGPASSWORD
react-cluster-ip-service.yaml
apiVersion: v1
kind: Service
metadata:
name: react-cluster-ip-service
spec:
type: ClusterIP
selector:
component: web
ports:
- port: 3000
targetPort: 3000
react-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: react-deployment
spec:
replicas: 3
selector:
matchLabels:
component: web
template:
metadata:
labels:
component: web
spec:
containers:
- name: react
image: simonjames/react-node-docker-kubernetes-app-react
ports:
- containerPort: 3000
ingres-服务.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- http:
paths:
- path: /?(.*)
backend:
serviceName: react-cluster-ip-service
servicePort: 3000
- path: /api/?(.*)
backend:
serviceName: express-cluster-ip-service
servicePort: 5000
当我浏览映射到我的 minikube 的 URL 时,出现 503 错误。这可能是什么原因造成的?配置有问题吗?当我使用 docker-compose.yaml 时,它运行良好。我正在使用类似的配置,那么这里的问题是什么?
答案1
A503 服务不可用错误是一个HTTP response status code
表明服务器暂时地无法处理请求。这可能是由于服务器超载或停机维护。
我对您的部署 yaml 进行了测试,但使用了不同的图像,因为我无法访问您提到的图像,但对我来说一切正常。入口和服务正确地将流量发送到适当的 pod。如果我删除其中一个服务,我在尝试访问它时会得到完全相同的错误。
这表明server connectivity issue
由于某些配置、端口不匹配或链中某处服务器关闭或无法访问,流量无法到达您的 pod。
我建议您首先使用不同的图像检查您的连接性,并确认与我的结果相同。作为第二次检查,您可能需要查看nginx controller pod
:
kubectl logs -n <namespace> <Ingress_nginx_controller_pod_name>