Linkerd 2.10 中文手册持续修正更新中:
您可以通过 ingress 暴露仪表板,而不是每次想要 查看发生了什么时都使用 linkerd viz dashboard
。这也会暴露 Grafana。
示例 ingress 定义是:
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: web-ingress-auth
namespace: linkerd-viz
data:
auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web-ingress
namespace: linkerd-viz
annotations:
kubernetes.io/ingress.class: 'nginx'
nginx.ingress.kubernetes.io/upstream-vhost: $service_name.$namespace.svc.cluster.local:8084
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Origin "";
proxy_hide_header l5d-remote-ip;
proxy_hide_header l5d-server-id;
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: web-ingress-auth
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
rules:
- host: dashboard.example.com
http:
paths:
- backend:
serviceName: web
servicePort: 8084
这会在 dashboard.example.com
上暴露仪表板, 并使用 admin/admin 通过 basic auth 对其进行保护。有关如何更改用户名和密码的详细信息,请查看 ingress-nginx 文档。
basic auth 的一种更安全的替代方法是使用身份验证代理,例如 oauth2-proxy。
有关如何在 kubernetes 中部署和配置 oauth2-proxy 的参考,请参阅 blog post by Don Bowman。
如果您通过 helm chart 部署 oauth2-proxy,则需要以下值:
config:
existingSecret: oauth2-proxy
configFile: |-
email_domains = [ "example.com" ]
upstreams = [ "file:///dev/null" ]
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
path: /oauth2
ingress:
hosts:
- linkerd.example.com
其中 oauth2-proxy
secret 将包含所需的 oauth2 config, 例如 client-id
client-secret
和 cookie-secret
。
设置后,示例 ingress 将是:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web
namespace: linkerd-viz
annotations:
kubernetes.io/ingress.class: 'nginx'
nginx.ingress.kubernetes.io/upstream-vhost: $service_name.$namespace.svc.cluster.local:8084
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Origin "";
proxy_hide_header l5d-remote-ip;
proxy_hide_header l5d-server-id;
nginx.ingress.kubernetes.io/auth-signin: https://$host/oauth2/start?rd=$escaped_request_uri
nginx.ingress.kubernetes.io/auth-url: https://$host/oauth2/auth
spec:
rules:
- host: linkerd.example.com
http:
paths:
- backend:
serviceName: web
servicePort: 8084
示例 ingress 定义是:
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: web-ingress-auth
namespace: linkerd-viz
data:
auth: YWRtaW46JGFwcjEkbjdDdTZnSGwkRTQ3b2dmN0NPOE5SWWpFakJPa1dNLgoK
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web-ingress
namespace: linkerd-viz
annotations:
kubernetes.io/ingress.class: 'traefik'
ingress.kubernetes.io/custom-request-headers: l5d-dst-override:web.linkerd-viz.svc.cluster.local:8084
traefik.ingress.kubernetes.io/auth-type: basic
traefik.ingress.kubernetes.io/auth-secret: web-ingress-auth
spec:
rules:
- host: dashboard.example.com
http:
paths:
- backend:
serviceName: web
servicePort: 8084
这会在 dashboard.example.com
上公开仪表板, 并使用 admin/admin 通过 basic auth 对其进行保护。有关如何更改用户名和密码的详细信息,请查看 Traefik 文档。
Ambassador 的工作原理是将mapping 定义 为服务的 annotation。
下面的 annotation 在 dashboard.example.com
上公开了仪表板。
annotations:
getambassador.io/config: |-
---
apiVersion: ambassador/v1
kind: Mapping
name: web-mapping
host: dashboard.example.com
prefix: /
host_rewrite: web.linkerd-viz.svc.cluster.local:8084
service: web.linkerd-viz.svc.cluster.local:8084
为防止 DNS-rebinding 攻击, 仪表板拒绝任何 Host
header 不是 localhost
、127.0.0.1
或 服务名称不是 web.linkerd-viz.svc
的请求。
请注意,此保护还涵盖 Grafana dashboard
。
上面的 ingress-nginx 配置使用 nginx.ingress.kubernetes.io/upstream-vhost
annotation 来正确设置上游 Host
header。另一方面,Traefik 不提供该选项,因此您必须手动设置所需的 Host
,如下所述。
如果您的 HTTP 客户端(Ingress 或其他方式)不允许重写 Host
header, 您可以更改仪表板服务器(dashboard server)使用的验证正则表达式, 该正则表达式通过 enforced-host
容器参数输入到 web
deployment 中。
如果您使用 Helm 管理 Linkerd,那么您可以使用 enforcedHostRegexp
值设置主机。
另一种方法是通过 Kustomize,如:自定义安装中所述,使用这样的覆盖:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
template:
spec:
containers:
- name: web
args:
- -linkerd-controller-api-addr=linkerd-controller-api.linkerd.svc.cluster.local:8085
- -linkerd-metrics-api-addr=metrics-api.linkerd-viz.svc.cluster.local:8085
- -cluster-domain=cluster.local
- -grafana-addr=grafana.linkerd-viz.svc.cluster.local:3000
- -controller-namespace=linkerd
- -viz-namespace=linkerd-viz
- -log-level=info
- -enforced-host=^dashboard\.example\.com$
如果要完全禁用 Host
header 检查,请为 -enforced-host
使用空字符串。