运行 入口控制器后面的 Kubernetes 集群中的 Graylog

Running Graylog in a Kubernetes cluster behind an ingress controller

我正在尝试按照 here 所述在我的 Kubernetes 集群中设置 Graylog。我 运行 遇到的问题是环境变量 GRAYLOG_HTTP_EXTERNAL_URI 的定义。文档告诉我输入 "my IP adress" 并且从我能够找到的内容来看,该变量用于告诉浏览器在哪里可以找到 Graylog API.

但是我的集群是通过NGINX反向代理作为ingress controller访问的,这意味着浏览器不能直接访问Graylog pod,更不能通过http访问,所以它不知道我应该取什么值屁股那里。我尝试了入口控制器的 public IP 地址,但我得到的只是一个 503。有没有办法允许访问 Graylog API,同时仍然保持服务受保护在入口控制器后面?

这真的取决于你如何暴露它。默认情况下,它不会暴露给外界。我们有 graylog3 类型 NodePort 的服务,所以我们只有一个内部 IP,可以从另一个 pod 访问或用于通过入口公开它。

$ kubectl get service -o wide
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                          AGE   SELECTOR
es6          NodePort    10.23.244.28    <none>        9200:30001/TCP,9300:30002/TCP    54m   service=es-deploy
graylog3     NodePort    10.23.242.128   <none>        9000:30003/TCP,12201:30004/TCP   54m   service=graylog-deploy
kubernetes   ClusterIP   10.23.240.1     <none>        443/TCP                          57m   <none>
mongo        ClusterIP   10.23.243.160   <none>        27017/TCP                        54m   service=mongo-deploy

如果我们从另一个 pod 卷曲此服务和端口,我们将得到以下输出:

$ kubectl exec -ti ubuntu -- curl 10.23.242.128:9000
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="robots" content="noindex, nofollow">
    <meta charset="UTF-8">
    <title>Graylog Web Interface</title>
    <link rel="shortcut icon" href="http://your_ip_address:30003/assets/favicon.png">

  </head>
  <body>
    <script src="http://your_ip_address:30003/config.js"></script>

    <script src="http://your_ip_address:30003/assets/vendor.4024e2a8db732781a971.js"></script>

    <script src="http://your_ip_address:30003/assets/polyfill.a5e2fb591e8fd54ee4ef.js"></script>

    <script src="http://your_ip_address:30003/assets/builtins.a5e2fb591e8fd54ee4ef.js"></script>

    <script src="http://your_ip_address:30003/assets/plugin/org.graylog.plugins.threatintel.ThreatIntelPlugin/plugin.org.graylog.plugins.threatintel.ThreatIntelPlugin.b864ba54b438ac0bdc48.js"></script>

    <script src="http://your_ip_address:30003/assets/plugin/org.graylog.plugins.collector.CollectorPlugin/plugin.org.graylog.plugins.collector.CollectorPlugin.bcc87290018e859a8a9e.js"></script>

    <script src="http://your_ip_address:30003/assets/plugin/org.graylog.aws.AWSPlugin/plugin.org.graylog.aws.AWSPlugin.8ae7cb13983ce33eeb5b.js"></script>

    <script src="http://your_ip_address:30003/assets/app.a5e2fb591e8fd54ee4ef.js"></script>

  </body>
</html>

可以看出,http://your_ip_address:30003有引用。如果我们这样离开它,应用程序就会崩溃,因为它引用了一些不存在的东西。

所以我将更改 2 项内容,通过入口使其从外部世界可见,并将 GRAYLOG_HTTP_EXTERNAL_URI 更改为正确的 IP 我将获得:

1 - 创建入口规则以公开 Graylog:

这是我的入口清单的样子

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: graylog
spec:
  backend:
    serviceName: graylog3
    servicePort: 9000
$ kubectl get ingresses 
NAME      HOSTS   ADDRESS          PORTS   AGE
graylog   *       34.107.139.231   80      56s

2 - 编辑我们的 GRAYLOG_HTTP_EXTERNAL_URI 并将 http://your_ip_address:30003 替换为 http://34.107.139.231:80

请注意,我在这里将端口从 30003 更改为 80,因为我们的入口规则在端口 80.

上公开
$ kubectl edit deployments graylog-deploy 

已进行更改,现在让我们从任何控制台卷曲此端口(给它一些时间以重新创建 pods):

$ curl 34.107.139.231:80
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="robots" content="noindex, nofollow">
    <meta charset="UTF-8">
    <title>Graylog Web Interface</title>
    <link rel="shortcut icon" href="http://34.107.139.231:80/assets/favicon.png">

  </head>
  <body>
    <script src="http://34.107.139.231:80/config.js"></script>

    <script src="http://34.107.139.231:80/assets/vendor.4024e2a8db732781a971.js"></script>

    <script src="http://34.107.139.231:80/assets/polyfill.a5e2fb591e8fd54ee4ef.js"></script>

    <script src="http://34.107.139.231:80/assets/builtins.a5e2fb591e8fd54ee4ef.js"></script>

    <script src="http://34.107.139.231:80/assets/plugin/org.graylog.plugins.threatintel.ThreatIntelPlugin/plugin.org.graylog.plugins.threatintel.ThreatIntelPlugin.b864ba54b438ac0bdc48.js"></script>

    <script src="http://34.107.139.231:80/assets/plugin/org.graylog.plugins.collector.CollectorPlugin/plugin.org.graylog.plugins.collector.CollectorPlugin.bcc87290018e859a8a9e.js"></script>

    <script src="http://34.107.139.231:80/assets/plugin/org.graylog.aws.AWSPlugin/plugin.org.graylog.aws.AWSPlugin.8ae7cb13983ce33eeb5b.js"></script>

    <script src="http://34.107.139.231:80/assets/app.a5e2fb591e8fd54ee4ef.js"></script>

  </body>
</html>

现在我们可以正常看到 http://34.107.139.231:80/ 页面可以完美加载了。

如果您有一个重定向到您的应用程序 IP 的域名,请将其放入此变量中。