公开集群内部的入口路径,但不公开?

时间:2019-03-17 17:22:21

标签: kubernetes kubernetes-helm kubernetes-ingress nginx-ingress

我有一个具有以下图表的吊舱:

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: nginx
    // ...
  paths:
    - /api/myservice

我的pod公开了api和/prometheus端点,可通过/api/myservice/prometheus访问该端点。

我想在群集中看到prometheus,但不能从/api/myservice/prometheus中看到。我该如何实现?

4 个答案:

答案 0 :(得分:2)

如果您只需要内部访问权限,我认为您不应该将其放入入口。您可以将DNS Service与Kubernetes集群一起使用。

如果您的prometheus服务运行的名称空间与工作窗格相同,则可以使用以下地址进行访问。

fit_text

如果您的prometheus服务在其他名称空间中运行,则可以使用:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:L60")) Is Nothing Then
        'Pass the Target to 'fit_text'
        Call fit_text(Target)
    End If
End Sub

Sub fit_text(Cell)
    'Instead of using ActiveCell, use Cell (which is the passed Target)
    MsgBox Cell.Characters.Count

    If Cell.Characters.Count > 100 Then
        Cell.Font.Size = 8
    Else
        Cell.Font.Size = 10
    End If
End Sub

访问该服务。

更新:

评论后更清楚地询问问题。

您可以这样编写另一条规则来隐藏http://prometheus-svc-name 端点:

http://prometheus-svc-name.prometheus-namespace.svc.cluster.local

nginx-inress将首先匹配最长的路线。它将/prometheus路由到404。See this documentation

答案 1 :(得分:2)

您可以添加一个Ingress规则,将端点重定向到默认后端:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: block
  annotations:
    ingress.kubernetes.io/ssl-redirect: "true"
    ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  - hosts:
    - myapp.to
  rules:
  - host: myapp.to
    http:
      paths:
      - path: /metrics
        backend:
          serviceName: ingress-default-backend
          servicePort: 8080

答案 2 :(得分:0)

实现此目的的最佳方法是从入口中删除Prometheus端点,如果您知道Prometheus支持使用服务上的注释进行自动发现,则为k8s自动发现配置Prometheus,然后在服务yaml文件中添加注释。 https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config

答案 3 :(得分:0)

将端点更改为指向您的API。 / api / myservice / my-api或使用应用程序根注释,指向/ api / myservice中的api:

nginx.ingress.kubernetes.io/app-root: /path/to/my/app/root/dir

此处有更多详细信息:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite

相关问题