Udostępnij za pośrednictwem


Włącz obsługę wielu przestrzeni nazw w klastrze AKS za pomocą AGIC

Przestrzenie nazw Kubernetes pozwalają na podział klastra Kubernetes i jego przydział do podgrup w ramach większego zespołu. Te podgrupy mogą następnie wdrażać infrastrukturę i zarządzać nią za pomocą bardziej precyzyjnych mechanizmów kontroli zasobów, zabezpieczeń i konfiguracji. Platforma Kubernetes umożliwia niezależne definiowanie co najmniej jednego zasobu Ingress w każdej przestrzeni nazw.

As of version 0.7 and greater, the Application Gateway Kubernetes Ingress Controller (AGIC) can ingest events from and observe multiple namespaces. If an Azure Kubernetes Service (AKS) administrator decides to use Azure Application Gateway as an ingress, all namespaces use the same deployment of Application Gateway. Pojedyncza instalacja programu AGIC monitoruje dostępne przestrzenie nazw i konfiguruje wdrożenie usługi Application Gateway skojarzone z nim.

Version 0.7 and greater of AGIC continues to exclusively observe the default namespace, unless you explicitly change it to one or more different namespaces in the Helm configuration.

Tip

Consider Application Gateway for Containers for your Kubernetes ingress solution. For more information, see Quickstart: Deploy Application Gateway for Containers ALB Controller.

Włącz obsługę wielu przestrzeni nazw

  1. Zmodyfikuj plik helm-config.yaml na jeden z następujących sposobów:

    • watchNamespace Usuń klucz całkowicie z pliku helm-config.yaml. Program AGIC obserwuje wszystkie przestrzenie nazw.
    • Set watchNamespace to an empty string. Program AGIC obserwuje wszystkie przestrzenie nazw.
    • Dodaj wiele przestrzeni nazw rozdzielonych przecinkami (na przykład watchNamespace: default,secondNamespace). AGIC observes these namespaces exclusively.
  2. Zastosuj zmiany szablonu programu Helm, uruchamiając polecenie helm install -f helm-config.yaml application-gateway-kubernetes-ingress/ingress-azure.

Po wdrożeniu programu AGIC z możliwością obserwowania wielu przestrzeni nazw wykonuje następujące akcje:

  • Wyświetla listę zasobów przychodzących ze wszystkich dostępnych przestrzeni nazw
  • Filters to ingress resources annotated with kubernetes.io/ingress.class: azure/application-gateway
  • Komponuje połączoną konfigurację usługi Application Gateway
  • Stosuje konfigurację do skojarzonego wdrożenia usługi Application Gateway za pośrednictwem usługi Azure Resource Manager

Zarządzanie konfliktowymi konfiguracjami

Multiple-namespaced ingress resources could instruct AGIC to create conflicting configurations for a single Application Gateway deployment. That is, two ingresses could claim the same domain.

W górnej części hierarchii program AGIC może tworzyć odbiorniki (adres IP, port i host) oraz reguły routingu (powiązanie odbiornika, puli zaplecza i ustawień PROTOKOŁU HTTP). Multiple namespaces and ingresses could share them.

Z drugiej strony program AGIC może tworzyć ścieżki, pule zaplecza, ustawienia HTTP i certyfikaty TLS tylko dla jednej przestrzeni nazw i usuwać duplikaty.

For example, consider the following duplicate ingress resources defined in the staging and production namespaces for www.contoso.com:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: websocket-ingress
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
    - host: www.contoso.com
      http:
        paths:
          - backend:
              serviceName: web-service
              servicePort: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: websocket-ingress
  namespace: production
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
    - host: www.contoso.com
      http:
        paths:
          - backend:
              serviceName: web-service
              servicePort: 80

Pomimo tego, że dwa zasoby wejściowe wymagają, aby ruch do www.contoso.com był kierowany do odpowiednich przestrzeni nazw Kubernetes, tylko jeden backend może ten ruch obsłużyć. AGIC tworzy konfigurację na zasadzie "pierwszy na wejściu, pierwszy na wyjściu" dla jednego z zasobów. Jeśli dwa zasoby wejściowe są tworzone w tym samym czasie, pierwszeństwo ma ten, który jest wcześniej w alfabecie. Based on this property, AGIC creates settings for the production ingress. Usługa Application Gateway jest skonfigurowana przy użyciu następujących zasobów:

  • Słuchacz: fl-www.contoso.com-80
  • Reguła routingu: rr-www.contoso.com-80
  • Backend pool: pool-production-contoso-web-service-80-bp-80
  • Ustawienia protokołu HTTP: bp-production-contoso-web-service-80-80-websocket-ingress
  • Sonda kondycji: pb-production-contoso-web-service-80-websocket-ingress

Uwaga

Z wyjątkiem odbiornika i reguły routingu, utworzone zasoby Application Gateway zawierają nazwę przestrzeni nazw (production), dla której zostały utworzone przez AGIC.

If the two ingress resources are introduced into the AKS cluster at different points in time, AGIC is likely to end up in a scenario where it reconfigures Application Gateway and reroutes traffic from namespace-B to namespace-A.

For example, if you add staging first, AGIC configures Application Gateway to route traffic to the staging backend pool. At a later stage, introducing production ingress causes AGIC to reprogram Application Gateway, which starts routing traffic to the production backend pool.

Ograniczanie dostępu do przestrzeni nazw

By default, AGIC configures Application Gateway based on annotated ingress within any namespace. Jeśli chcesz ograniczyć to zachowanie, masz następujące opcje:

  • Ogranicz przestrzenie nazw, jawnie definiując przestrzenie nazw, które program AGIC powinien obserwować za pośrednictwem watchNamespace klucza YAML w pliku helm-config.yaml.
  • Użyj obiektów Role i RoleBinding, aby ograniczyć AGIC do określonych przestrzeni nazw.

Przykładowy plik konfiguracji programu Helm

    # This file contains the essential configs for the ingress controller helm chart

    # Verbosity level of the App Gateway Ingress Controller
    verbosityLevel: 3
    
    ################################################################################
    # Specify which application gateway the ingress controller manages
    #
    appgw:
        subscriptionId: <subscriptionId>
        resourceGroup: <resourceGroupName>
        name: <applicationGatewayName>
    
        # Setting appgw.shared to "true" creates an AzureIngressProhibitedTarget CRD.
        # This prohibits AGIC from applying config for any host/path.
        # Use "kubectl get AzureIngressProhibitedTargets" to view and change this.
        shared: false
    
    ################################################################################
    # Specify which kubernetes namespace the ingress controller watches
    # Default value is "default"
    # Leaving this variable out or setting it to blank or empty string would
    # result in Ingress Controller observing all accessible namespaces.
    #
    # kubernetes:
    #   watchNamespace: <namespace>
    
    ################################################################################
    # Specify the authentication with Azure Resource Manager
    #
    # Two authentication methods are available:
    # - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
    armAuth:
        type: aadPodIdentity
        identityResourceID: <identityResourceId>
        identityClientID:  <identityClientId>
    
    ## Alternatively you can use Service Principal credentials
    # armAuth:
    #    type: servicePrincipal
    #    secretJSON: <<Generate this value with: "az ad sp create-for-rbac --subscription <subscription-uuid> --role Contributor --sdk-auth | base64 -w0" >>
    
    ################################################################################
    # Specify if the cluster is Kubernetes RBAC enabled or not
    rbac:
        enabled: false # true/false
    
    # Specify aks cluster related information. THIS IS BEING DEPRECATED.
    aksClusterConfiguration:
        apiServerAddress: <aks-api-server-address>