gpt4 book ai didi

proxy - 如何通过kubectl代理访问该Kubernetes服务?

转载 作者:行者123 更新时间:2023-12-04 00:43:49 32 4
gpt4 key购买 nike

我想通过kubectl proxy server访问我的Grafana Kubernetes服务,但是由于某种原因,即使我可以将其用于其他服务,该服务也无法使用。给定以下服务定义,为什么在http://localhost:8001/api/v1/proxy/namespaces/monitoring/services/grafana上不可用?

grafana-service.yaml

apiVersion: v1
kind: Service
metadata:
namespace: monitoring
name: grafana
labels:
app: grafana
spec:
type: NodePort
ports:
- name: web
port: 3000
protocol: TCP
nodePort: 30902
selector:
app: grafana

grafana-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: monitoring
name: grafana
spec:
replicas: 1
template:
metadata:
labels:
app: grafana
spec:
containers:
- name: grafana
image: grafana/grafana:4.1.1
env:
- name: GF_AUTH_BASIC_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "true"
- name: GF_SECURITY_ADMIN_USER
valueFrom:
secretKeyRef:
name: grafana-credentials
key: user
- name: GF_SECURITY_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: grafana-credentials
key: password
volumeMounts:
- name: grafana-storage
mountPath: /var/grafana-storage
ports:
- name: web
containerPort: 3000
resources:
requests:
memory: 100Mi
cpu: 100m
limits:
memory: 200Mi
cpu: 200m
- name: grafana-watcher
image: quay.io/coreos/grafana-watcher:v0.0.5
args:
- '--watch-dir=/var/grafana-dashboards'
- '--grafana-url=http://localhost:3000'
env:
- name: GRAFANA_USER
valueFrom:
secretKeyRef:
name: grafana-credentials
key: user
- name: GRAFANA_PASSWORD
valueFrom:
secretKeyRef:
name: grafana-credentials
key: password
resources:
requests:
memory: "16Mi"
cpu: "50m"
limits:
memory: "32Mi"
cpu: "100m"
volumeMounts:
- name: grafana-dashboards
mountPath: /var/grafana-dashboards
volumes:
- name: grafana-storage
emptyDir: {}
- name: grafana-dashboards
configMap:
name: grafana-dashboards

访问上述URL时出现的错误是“服务无可用端点” grafana”,错误代码503。

最佳答案

正如Michael所说,您的标签或 namespace 很可能不匹配。但是,除此之外,请记住,即使在修复端点时,后面的网址(http://localhost:8001/api/v1/proxy/namespaces/monitoring/services/grafana)也可能无法正常工作。

取决于您的root_url和/或static_root_path grafana配置设置,尝试登录时,您可能会得到grafana尝试POST到http://localhost:8001/login并获得404。

尝试改用kubectl port-forward:
kubectl -n monitoring port-forward [grafana-pod-name] 3000
然后通过http://localhost:3000/访问grafana

https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

关于proxy - 如何通过kubectl代理访问该Kubernetes服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45172008/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com