简体   繁体   English

只允许使用 k8s 入口对某些路径的请求

[英]Only allow requests to certain paths using k8s ingress

I've set up an ingress to route traffic to my http server, however I would like to leave some routes inaccessible from outside of the cluster.我已经设置了一个入口来将流量路由到我的 http 服务器,但是我想让一些路由无法从集群外部访问。

Example routes:示例路线:

/status -> end point to determine service status

/users/names -> returns users

/users/ages -> returns ages

current ingress:当前入口:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: my-namespace
  name: my-app-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: localhost
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: my-service
            port:
              number: 8080

this works currently but leaves all routes accessible.这目前有效,但所有路线都可以访问。 What I want to do is only have routes that fall under the /users path open, so that would be both /users/names and /users/ages .我想要做的只是打开/users路径下的路由,所以这将是/users/names/users/ages That would leave /status inaccessible from outside of the cluster.这将使/status无法从集群外部访问。 Is this achievable from changing the ingress configuration?这可以通过更改入口配置来实现吗? Any help would be appreciated.任何帮助,将不胜感激。

Just specify the path that you want to expose via the ingress like this:只需指定要通过入口公开的路径,如下所示:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: my-namespace
  name: my-app-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: localhost
    http:
      paths:
      - pathType: Prefix
        path: /users # <- add the path here
        backend:
          service:
            name: my-service
            port:
              number: 8080

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM