服务.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: {}
入口-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 getting Endpoints for Service "test/dashboard": no object matching key "test/dashboard" in local store"
作为参考,我的所有清单都部署在 K8 的 test 命名空间下。
我在网上找到的大多数参考资料都在谈论确保服务具有有效的端点。
kubectl 获取端点 --namespace 测试
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>
据我所知,我的服务确实有一个有效的端点。我错过了什么?
正如评论部分提到的,问题的根本原因是入口配置错误。
其中一条
Ingress
路径是指向不存在的服务 -dashboard
. 一旦更改为grafana
,入口应该可以正常工作。