简体   繁体   English

Kubernetes 仪表板通过 kubectl 代理 - 端口混淆

[英]Kubernetes dashboard through kubectl proxy - port confusion

I have seen that the standard way to access http services through the kubectl proxy is the following: http://api.host/api/v1/namespaces/NAMESPACE/services/SERVICE_NAME:SERVICE_PORT/proxy/我看到通过kubectl代理访问http服务的标准方式如下: http://api.host/api/v1/namespaces/NAMESPACE/services/SERVICE_NAME:SERVICE_PORT/proxy/

Why is it that the kubernetes-dashboard uses https:kubernetes-dashboard: for SERVICE_NAME:SERVICE_PORT ?为什么 kubernetes-dashboard 使用https:kubernetes-dashboard: for SERVICE_NAME:SERVICE_PORT

I would assume from the following that it would be kubernetes_dashboard:443 .我会从以下假设它是kubernetes_dashboard:443

kubectl -n kube-system get service kubernetes-dashboard -o wide
NAME                   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE   SELECTOR
kubernetes-dashboard   ClusterIP   10.233.50.212   <none>        443:31663/TCP   15d   k8s-app=kubernetes-dashboard

Additionally, what is the meaning of the port show 443:31663 when all other services will just have x/TCP ( x being one number instead of x : y )此外,当所有其他服务都只有x/TCP时,端口显示443:31663的含义是什么( x是一个数字而不是x : y

Lastly, kubectl cluster-info will show最后, kubectl cluster-info将显示

Kubernetes master is running at https://x.x.x.x:x
kubernetes-dashboard is running at https://x.x.x.x:x/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy

I have created a simple service but it does not show here and I am confused how to determine what services show here or not.我创建了一个简单的服务,但它没有在这里显示,我很困惑如何确定这里显示的服务。

Why is it that the kubernetes-dashboard uses https:kubernetes-dashboard: for SERVICE_NAME:SERVICE_PORT?为什么 kubernetes-dashboard 使用 https:kubernetes-dashboard: for SERVICE_NAME:SERVICE_PORT?

Additionally, what is the meaning of the port show 443:31663 when all other services will just have x/TCP (x being one number instead of x:y)此外,当所有其他服务都只有 x/TCP(x 是一个数字而不是 x:y)时,端口显示 443:31663 的含义是什么?

As described in Manually constructing apiserver proxy URLs , the default way is手动构建 apiserver 代理 URL中所述,默认方式是

http://kubernetes_master_address/api/v1/namespaces/namespace_name/services/service_name[:port_name]/proxy

By default, the API server proxies to your service using http.默认情况下,API 服务器使用 http 代理您的服务。 To use https, prefix the service name with https::要使用 https,请在服务名称前加上 https::

http://kubernetes_master_address/api/v1/namespaces/namespace_name/services/https:service_name:[port_name]/proxy

The supported formats for the name segment of the URL are: URL 的名称段支持的格式为:

<service_name> - proxies to the default or unnamed port using http <service_name> - 使用 http 代理到默认或未命名端口

<service_name>:<port_name> - proxies to the specified port using http <service_name>:<port_name> - 使用 http 代理到指定端口

https:<service_name>: - proxies to the default or unnamed port using https (note the trailing colon) https:<service_name>: - 使用 https 代理到默认或未命名端口(注意尾随冒号)

https:<service_name>:<port_name> - proxies to the specified port using https https:<service_name>:<port_name> - 使用 https 代理到指定端口

Next:下一个:

I have created a simple service but it does not show here and I am confused how to determine what services show here or not.我创建了一个简单的服务,但它没有在这里显示,我很困惑如何确定这里显示的服务。

What is what I found and tested for you:我为您找到并测试了什么:

cluster-info API reference : 集群信息 API 参考

Display addresses of the master and services with label kubernetes.io/cluster-service=true To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.使用 label kubernetes.io/cluster-service=true显示主服务器和服务的地址 要进一步调试和诊断集群问题,请使用“kubectl cluster-info dump”。

So, as soon as you add kubernetes.io/cluster-service: "true" label - the service starts to be seen under kubectl cluster-info .因此,只要您添加kubernetes.io/cluster-service: "true" label - 就会开始在kubectl cluster-info下看到该服务。

BUT.!但。! There is an expected behavior when you see that you service disappear from output in couple of minutes.当您看到您的服务在几分钟内从 output 消失时,这是一种预期行为。 Explanation has been found here - I only copy paste it here for future reference.已在此处找到说明-我仅在此处复制粘贴以供将来参考。

The other part is the addon manager.另一部分是插件管理器。 It uses this annotation to synchronizes the cluster state with static manifest files.它使用此注释将集群 state 与 static 清单文件同步。 The behavior was something like this:行为是这样的:

1) addon manager reads a yaml from disk -> deploys the contents 1) 插件管理器从磁盘读取 yaml -> 部署内容

2) addon manager reads all deployments from api server with annotation cluster-service:true -> deletes all that do not exist as files 2) 插件管理器从 api 服务器读取所有部署,带有注释 cluster-service:true -> 删除所有不作为文件存在的文件

As a result, if you add this annotation, addon manager will remove dashboard after a minute or so.因此,如果您添加此注释,插件管理器将在一分钟左右后删除仪表板。

So,所以,

dashboard is deployed after cluster creation -> annotation should not be set: https://github.com/kubernetes/dashboard/blob/b98d167dadaafb665a28091d1e975cf74eb31c94/src/deploy/kubernetes-dashboard.yaml仪表板在集群创建后部署 -> 不应设置注释: https://github.com/kubernetes/dashboard/blob/b98d167dadaafb665a28091d1e975cf74eb31c94/src/deploy/kubernetes-dashboard.Z6EEDC03A678A69D73C03A678A69D73C03A678A69D73C

dashboard is deployed part of cluster creation -> annotation should be set: https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dashboard/dashboard-controller.yaml仪表板是集群创建的一部分-> 应设置注释: https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dashboard/dashboard-controller.yaml

At least this was the behavior some time ago.至少这是前一段时间的行为。 I think kubeadm does not use addon-manager.我认为 kubeadm 不使用插件管理器。 But it is still part of kube-up script.但它仍然是 kube-up 脚本的一部分。

Solution for this behavior also exists: add additional label addonmanager.kubernetes.io/mode: EnsureExists此行为的解决方案也存在:添加额外的 label addonmanager.kubernetes.io/mode: EnsureExists

Explanation is here解释在这里

You final service should look like:您的最终服务应如下所示:

# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: EnsureExists
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard



kubectl get svc kubernetes-dashboard -n kube-system -o yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"EnsureExists","k8s-app":"kubernetes-dashboard","kubernetes.io/cluster-service":"true"},"name":"kubernetes-dashboard","namespace":"kube-system"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
    k8s-app: kubernetes-dashboard
    kubernetes.io/cluster-service: "true"



kubectl cluster-info
Kubernetes master is running at https://*.*.*.*
...
kubernetes-dashboard is running at https://*.*.*.*/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无需kubectl代理即可访问Kubernetes仪表板 - Enable access to Kubernetes Dashboard without kubectl proxy 127.0.0.1:8001当Kubectl代理访问kubernetes仪表板时拒绝连接 - 127.0.0.1:8001 refused to connect when kubectl proxy to access kubernetes dashboard 无法使用 kubectl 代理以非管理员用户身份连接到 Kubernetes 仪表板 - Cannot connect to Kubernetes Dashboard as non-admin user with kubectl proxy 无法通过 Web 浏览器使用 kubectl 代理访问 kubernetes 仪表板 - Cannot access kubernetes dashboard with kubectl proxy via a web browser kubernetes 仪表板可通过 curl 访问,但不能通过 kubectl 代理访问 chrome/firefox - kubernetes dashboard reachable with curl but not chrome/firefox via kubectl proxy 通过Nginx代理访问Kubernetes仪表板 - Visit Kubernetes dashboard through nginx proxy Kubernetes:在没有主机和代理的情况下通过 Ingress 路由 Kubernetes 仪表板 - Kubernetes: Route Kubernetes dashboard through Ingress with out host and without proxy Kubernetes UI:kubectl代理错误 - Kubernetes UI: error in kubectl proxy Kubernetes:关注 kubectl 代理日志 - Kubernetes: Follow kubectl proxy logs docker 桌面中的 kubectl Dashboard 需要代理 - kubectl Dashboard in docker desktop needs proxy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM