在Kubernetes控制器中搜索注解

46qrfjad  于 2022-10-06  发布在  Kubernetes
关注(0)|答案(1)|浏览(153)

我正在尝试寻找注解,以便在Nginx控制器中执行一些基本身份验证。互联网上的大多数资源都指定了这个注解:“nginx.ingress.kuberenetes.io/...”

而我发现在nginx文档:https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/中,它被切换为“nginx.org”

在外部文档中寻找答案似乎有点绕道。有没有一种方法可以用本地命令浏览Contoller上支持的注解,也许是类似kubectl EXPLAIN的命令?

有什么主意吗?

zbdgwd5y

zbdgwd5y1#

您可以使用kubectl explain ingress,但它将只显示关于入口的Kubernetes资源的文档,类似于

KIND:     Ingress
VERSION:  networking.k8s.io/v1

DESCRIPTION:
     Ingress is a collection of rules that allow inbound connections to reach
     the endpoints defined by a backend. An Ingress can be configured to give
     services externally-reachable urls, load balance traffic, terminate SSL,
     offer name based virtual hosting etc.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec <Object>
     Spec is the desired state of the Ingress. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

   status   <Object>
     Status is the current state of the Ingress. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

简而言之,为了更好地进行注解,请检查舵图和官方文件

以下是向入口添加基本身份验证的方法

首先,创建基本身份验证密钥

htpasswd -c auth admin
kubectl create secret generic basic-auth --from-file=auth

然后在注解中引用这个秘密

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: basic-auth
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required to access Linkerd'
  name: linker-basicauth-ingress
  namespace: linkerd-viz
spec:
  tls:
    - hosts:
        - mybasic-auth.example.com
      secretName: ingres-tls-secret
  rules:
    - host: mybasic-auth.example.com
      http:
        paths:
          - backend:
              service:
                name: web
                port:
                  number:  8084
            path: /
            pathType: Prefix

nginx-configuration/annotations.md

相关问题