服务.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
io.kompose.service: grafana
name: grafana
spec:
ports:
- name: "3000"
port: 3000
targetPort: 3000
selector:
io.kompose.service: grafana
status:
loadBalancer: {}
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: grafana
name: grafana
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: grafana
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: grafana
spec:
containers:
- env:
- name: GF_SERVER_DOMAIN
# value: "testing.esamir.com"
value: "direct.esamir.com"
- name: GF_SERVER_ROOT_URL
value: "%(protocol)s://%(domain)s:%(http_port)s/"
- name: GF_SERVER_SERVE_FROM_SUB_PATH
value: "true"
- name: GF_DATABASE_URL
valueFrom:
configMapKeyRef:
name: grafanaconfig
key: url
image: grafana/grafana:7.4.0-ubuntu
name: grafana
ports:
- containerPort: 3000
resources: {}
restartPolicy: Always
status: {}
ingress-nginx 配置:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: hello-kubernetes-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: testing1.com
http:
paths:
- backend:
serviceName: hello-kubernetes-second
servicePort: 80
- host: testing2.com
http:
paths:
- backend:
serviceName: dashboard
servicePort: 3000
如果我连接到 testing1.com 上的 http 或 https,它正在运行一个简单的 hello-world kubernetes 应用程序。一切都运行正常。
如果我通过 https 或 http 连接到 testin2.com,我会收到 503 错误。“503 服务暂时不可用”
查看日志时,我发现了此错误:“2021-02-09 15:34:25.309 PSTError 获取服务“test/dashboard”的端点:本地存储中没有与键“test/dashboard”匹配的对象”
作为参考,我的所有清单都部署在 K8 中的测试命名空间下。
我在网上找到的大多数参考资料都在谈论确保服务具有有效的端点。
kubectl 获取端点--命名空间测试
NAME ENDPOINTS AGE
grafana 10.68.5.23:3000 6h4m
hello-kubernetes-second 10.68.3.9:8080,10.68.5.5:8080,10.68.6.6:8080 6h22m
nginx-ingress-nginx-controller 10.68.5.8:443,10.68.5.8:80 6h20m
nginx-ingress-nginx-controller-admission 10.68.5.8:8443 6h20m
kubectl 描述 svc grafana-n 测试
Namespace: test
Labels: io.kompose.service=grafana
Annotations: <none>
Selector: io.kompose.service=grafana
Type: ClusterIP
IP: 10.71.248.111
Port: 3000 3000/TCP
TargetPort: 3000/TCP
Endpoints: 10.68.5.23:3000
Session Affinity: None
Events: <none>
据我所知,我的服务确实有一个有效端点。我遗漏了什么?
答案1
正如评论部分所提到的,问题的根本原因是入口配置错误。
其中一条Ingress
路径指向不存在的服务 - dashboard
。一旦将其更改为grafana
,Ingress 应该可以正常工作。