2.7 在 Azure Kubernetes Services 中部署 Identity Console

Azure Kubernetes Services (AKS) 是一项托管式 Kubernetes 服务,可用于部署和管理群集。本部分包含下列操作过程的信息:

2.7.1 在 AKS 群集中部署 Identity Console

本部分介绍下列在 AKS 群集中部署 Identity Console 的操作过程:

创建 Azure 容器注册表 (ACR)

Azure 容器注册表 (ACR) 是一个基于 Azure 的专用注册表,适用于 Docker 容器映像。

有关更多详细步骤,请参阅 Create container registry - Portal(创建容器注册表 - 门户)中的 Create an Azure container registry using the Azure portal(使用 Azure 门户创建 Azure 容器注册表)部分,或执行以下步骤创建 Azure 容器注册表 (ACR):

  1. 登录到 Azure 门户

  2. 转到 Create a resource(创建资源)> Containers(容器)> Container Registry(容器注册表)。

  3. Basics(基本信息)选项卡中,指定 Resource group(资源组)和 Registry name(注册表名称)的值。注册表名称在 Azure 中必须是唯一的,并且至少包含 5 个字母数字字符,最多包含 50 个字母数字字符。

    接受其余设置的默认值。

  4. 单击 Review + create(查看 + 创建)。

  5. 单击创建

  6. 登录到 Azure CLI,运行以下命令以登录到 Azure 容器注册表

    az acr login --name registryname

    例如:

    az acr login --name < idconsole >
  7. 使用以下命令检索 Azure 容器注册表的登录服务器:

    az acr show --name registryname --query loginServer --output table

    例如:

    az acr show --name < idconsole > --query loginServer --output table
  8. 使用以下命令用 ACR 登录服务器的名称 (registryname.azureacr.io) 标记 Identity Console 的本地映像:

    docker tag idconsole-image <login server>/idconsole-image

    例如,

    docker tag identityconsole:<version> registryname.azurecr.io/identityconsole:<version>
  9. 将标记的映像推送到注册表。

    docker push <login server>/idconsole: <version>

    例如,

    docker push registryname.azurecr.io/identityconsole:<version>
  10. 使用以下命令检索注册表中的映像列表:

    az acr show --name registryname --query loginServer --output table

设置 Kubernetes 群集

使用 Azure 门户或 CLI 创建 kubernetes 服务资源。

有关在 Azure 中创建一个包含节点的 Kubernetes 服务资源的更多详细步骤,请参阅 Azure Quickstart(Azure 快速入门)中的 Create an AKS Cluster(创建一个 AKS 群集)。

注:

  • 确保选择 Azure CNI 作为网络。

  • 选择现有虚拟网络(其中 eDirectory 服务器部署在子网中)。

  • 选择 Identity Console 映像在其中可用的现有容器注册表。

创建标准库存单位 (SKU) 公共 IP 地址

Kubernetes 群集资源组下的公共 IP 地址资源充当应用程序的负载均衡器 IP。

有关详细步骤,请参阅 Create public IP address – Portal(创建公共 IP 地址 - 门户)中的 Create a public IP address using the Azure portal(使用 Azure 门户创建公共 IP 地址)。

设置云壳层并连接到 Kubernetes 群集

使用 Azure 门户中可用于所有操作的云壳层。

若要在 Azure 门户中设置云壳层,请参阅 Bash – Quickstart(Bash – 快速入门)中的 Start Cloud Shell(启动云壳层)部分,或执行以下步骤来设置云壳层并连接到 Kubernetes 群集:

  1. 在 Azure 门户中,单击 按钮打开云壳层。

    注:要管理 Kubernetes 群集,请使用 Kubernetes 命令行客户端 kubectl。如果使用的是 Azure Cloud Shell,则已安装 kubectl。

  2. 使用以下命令配置 kubectl 以连接到您的 Kubernetes 群集:

    az aks get-credentials --resource-group "resource group name" --name "Kubernetes cluster name"

    例如,

    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
  3. 使用以下命令校验群集节点的列表:

    kubectl get nodes

部署应用程序

要部署 Identity Console,您可以使用 idc-services.yamlidc-statefulset.yamlidc-storageclass.yamlidc-pvc.yaml 示例文件。

您还可以根据要求创建自己的 yaml 文件。

  1. 使用以下命令创建储存类资源:

    kubectl apply -f <location of the YAML file>

    例如,

    kubectl apply -f idc-storageclass.yaml

    (可选)有关如何通过 Azure 文件共享动态创建和使用持久性卷的更多信息,请参阅 Dynamically create and use a persistent volume with Azure Files in Azure Kubernetes Service (AKS)(在 Azure Kubernetes Service (AKS) 中通过 Azure 文件动态创建和使用持久性卷)

    示例储存类资源文件如下所示:

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: azurefilesc
    provisioner: kubernetes.io/azure-file
    mountOptions:
      - dir_mode=0777
      - file_mode=0777
      - uid=0
      - gid=0
      - mfsymlinks
      - cache=strict
      - actimeo=30
    parameters:
      skuName: Standard_LRS
      shareName: fileshare
    ~

    储存类资源支持动态储存供应。它用于定义如何创建 Azure 文件共享。

  2. 使用以下命令查看储存类的细节:

    kubectl get sc
  3. 使用 idc-pvc.yaml 文件创建一个 pvc 资源:

    kubectl apply -f <location of the YAML file>

    例如,

    kubectl apply -f idc.pvc.yaml

    示例 pvc 资源文件如下所示:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvcforsc
    spec:
      accessModes:
        - ReadWriteMany
      storageClassName: azurefilesc
      resources:
        requests:
          storage: 5Gi

    持久性卷声明资源创建文件共享。持久性卷声明 (PVC) 使用储存类对象动态供应 Azure 文件共享。

  4. 将 edirapi.conf、证书颁发机构证书和服务器证书上传到云壳层。

    单击云壳层上的 Upload/Download files(上载/下载文件)按钮图标 ,然后上载 edirapi.confSSCert.pemkeys.pfx 文件。

    注:edirapi.conf 有一个参数“原点”。在这里,我们需要提供用于访问 Identity Console 应用程序的 IP 地址。(使用在 创建标准库存单位 (SKU) 公共 IP 地址 部分中创建的 IP 地址。)

    Identity Console 部署需要服务器证书 (keys.pfx)。

    创建服务器证书时,请确保在主题备用名称中提供有效的 DNS 名称。

    构建有效 DNS 名称的步骤:

    使用 StatefulSet 部署的典型 pod 具有如下所示的 DNS 名称 - {statefulsetname}-{ordinal}.{servicename}.{namespace}.svc.cluster.local

    • 如果 idconsole-statefulset.yaml 文件中的 StatefulSet 名称是 idconsole-app,则 statefulsetname = idconsole-app

    • 如果是第一个 Pod,则序号 = 0

    • 如果将 idconsole -statefulset.yaml 文件中的 serviceName 定义为 idconsole,则 serviceName = idconsole

    • 如果是默认命名空间,则 namespace=default

    输出:idconsole-app-0.idcosole.default.svc.cluster.local

  5. 在 Kubernetes 群集中创建一个 configmap 资源,该资源将储存配置文件以及证书。

    在运行该命令之前,请确保目录中存在文件 edirapi.confSSCert.pemkeys.pfx

    kubectl create configmap <confgimapName> --from-file= "path where the files are present"

    例如,

    kubectl create configmap config-data --from-file=/data
  6. 查看 configmap 对象的细节,使用 kubectl 描述命令:

    kubectl describe configmap <configmapName>

    例如,

    kubectl describe configmap confg-data
  7. 创建 StatefulSet 资源以部署容器。

    运行以下命令以部署容器:

    kubectl apply -f <location of the YAML file>

    例如,

    kubectl apply -f idc-statefulset.yaml

    示例 StatefulSet 资源文件如下所示:

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: idconsole-app
    spec:
      serviceName: idconsole
      selector:
        matchLabels:
          app: idconsole
      replicas: 1
      template:
        metadata:
          labels:
            app: idconsole
        spec:
          containers:
          - name: idconsole-container
            image: registryname.azurecr.io/identityconsole:<version>
            env:
            - name: ACCEPT_EULA
              value: "Y"
            ports:
            - containerPort: 9000
            volumeMounts:
              - name: configfiles
                mountPath: /config/data
              - name: datapersistenceandlog
                mountPath: /config
                subPath: log
          volumes:
            - name: configfiles
              configMap:
                name: config-data
            - name: datapersistenceandlog
              persistentVolumeClaim:
                claimName: pvcforsc
  8. 运行以下命令校验已部署 Pod 的状态:

    kubectl get pods -o wide
  9. 创建 loadBalancer 类型的服务资源。

    yaml 文件中指定的服务类型是 loadBalancer。

    使用以下命令创建服务资源:

    kubectl apply -f <location of the YAML file>

    例如,

    kubectl apply -f ids-service.yaml

    示例服务资源文件如下所示:

    apiVersion: v1
    kind: Service
    metadata:
      name: idconsole-service
      labels:
        run: idconsole-service
    spec:
      type: LoadBalancer
      loadBalancerIP: xx.xx.xx.xx
      selector:
        app: idconsole
      ports:
       - port: 9000
         targetPort: 9000
         protocol: TCP

    使用以下命令检查外部 IP 地址(或 loadBalancerIP):

    kubectl get svc -o wide
  10. 使用外部 IP(或 loadBalancerIP 地址)启动 URL。

    例如,

    https://<外部 IP>:9000/identityconsole