本文介绍了如何使用 Bicep 模板将 Open Service Mesh 加载项部署到 Azure Kubernetes 服务 (AKS) 中。
重要
根据群集运行的 Kubernetes 版本,OSM 加载项会安装不同版本的 OSM。
Kubernetes 版本 | 安装的 OSM 版本 |
---|---|
1.24.0 或更高版本 | 1.2.5 |
介于 1.23.5 和 1.24.0 之间 | 1.1.3 |
低于 1.23.5 | 1.0.0 |
如果相应的 AKS 版本已结束生命周期,则较旧版本的 OSM 可能无法安装或获得主动支持。 有关 AKS 版本支持窗口的信息,可以查看 AKS Kubernetes 发布日历。
Bicep 是一种特定于域的语言,它使用声明性语法来部署 Azure 资源。 可以使用 Bicep 代替创建 Azure 资源管理器模板来部署基础架构即代码 Azure 资源。
在开始之前,请确保满足以下先决条件:
- Azure CLI 2.20.0 或更高版本 运行
az --version
即可查找版本。 如果需要进行安装或升级,请参阅安装 Azure CLI。 - 用于部署 AKS 的 SSH 公钥
- 带有 Bash 终端的 Visual Studio Code。
- Visual Studio Code Bicep 扩展。
若要部署新的 AKS 群集,请在创建群集时启用 OSM 加载项。 以下说明使用通用 Bicep 模板,该模板通过使用临时磁盘和 kubenet
容器网络接口部署 AKS 群集,然后启用 OSM 加载项。 要了解更高级的部署方案,请参阅什么是 Bicep?
使用
az group create
命令创建资源组。az group create --name <my-osm-bicep-aks-cluster-rg> --location <azure-region>
创建一个目录来存储必要的 Bicep 部署文件。 以下示例创建名为 bicep-osm-aks-addon 的目录并切换到该目录:
mkdir bicep-osm-aks-addon cd bicep-osm-aks-addon
创建 main 文件和参数文件。
touch osm.aks.bicep && touch osm.aks.parameters.json
打开 osm.aks.bicep 文件,并将以下内容复制到其中:
// /aks/troubleshooting#what-naming-restrictions-are-enforced-for-aks-resources-and-parameters @minLength(3) @maxLength(63) @description('Provide a name for the AKS cluster. The only allowed characters are letters, numbers, dashes, and underscore. The first and last character must be a letter or a number.') param clusterName string @minLength(3) @maxLength(54) @description('Provide a name for the AKS dnsPrefix. Valid characters include alphanumeric values and hyphens (-). The dnsPrefix can\'t include special characters such as a period (.)') param clusterDNSPrefix string param k8Version string param sshPubKey string param location string param adminUsername string resource aksCluster 'Microsoft.ContainerService/managedClusters@2021-03-01' = { name: clusterName location: location identity: { type: 'SystemAssigned' } properties: { kubernetesVersion: k8Version dnsPrefix: clusterDNSPrefix enableRBAC: true agentPoolProfiles: [ { name: 'agentpool' count: 3 vmSize: 'Standard_DS2_v2' osDiskSizeGB: 30 osDiskType: 'Ephemeral' osType: 'Linux' mode: 'System' } ] linuxProfile: { adminUsername: adminUserName ssh: { publicKeys: [ { keyData: sshPubKey } ] } } addonProfiles: { openServiceMesh: { enabled: true config: {} } } } }
打开 osm.aks.parameters.json 文件,并将以下内容复制到其中。 请确保将部署参数值替换为自己的值。
备注
osm.aks.parameters.json 文件是 Bicep 部署所需的示例模板参数文件。 专门为部署环境更新参数。 需要为其添加值的参数包括:
clusterName
、clusterDNSPrefix
、k8Version
、sshPubKey
、location
和adminUsername
。 若要在区域中查找支持的 Kubernetes 版本列表,请使用az aks get-versions --location <region>
命令。{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "clusterName": { "value": "<YOUR CLUSTER NAME HERE>" }, "clusterDNSPrefix": { "value": "<YOUR CLUSTER DNS PREFIX HERE>" }, "k8Version": { "value": "<YOUR SUPPORTED KUBERNETES VERSION HERE>" }, "sshPubKey": { "value": "<YOUR SSH KEY HERE>" }, "location": { "value": "<YOUR AZURE REGION HERE>" }, "adminUsername": { "value": "<YOUR ADMIN USERNAME HERE>" } } }
打开终端并使用
az login
命令对 Azure CLI 的 Azure 帐户进行身份验证。使用
az deployment group create
命令部署 Bicep 文件。az deployment group create \ --name OSMBicepDeployment \ --resource-group osm-bicep-test \ --template-file osm.aks.bicep \ --parameters @osm.aks.parameters.json
首先,查询群集的加载项配置文件,以检查已安装加载项的启用状态。 以下命令应返回
true
:az aks list -g <my-osm-aks-cluster-rg> -o json | jq -r '.[].addonProfiles.openServiceMesh.enabled'
使用以下 命令获取 osm-controller
kubectl
的状态。kubectl get deployments -n kube-system --selector app=osm-controller kubectl get pods -n kube-system --selector app=osm-controller kubectl get services -n kube-system --selector app=osm-controller
可以通过 OSM MeshConfig 资源来配置 OSM 控制器,并可以通过 Azure CLI 查看 OSM 控制器的配置设置。
使用
kubectl get
命令查看 OSM 控制器的配置设置。kubectl get meshconfig osm-mesh-config -n kube-system -o yaml
下面是 MeshConfig 的示例输出:
apiVersion: config.openservicemesh.io/v1alpha1 kind: MeshConfig metadata: creationTimestamp: "0000-00-00A00:00:00A" generation: 1 name: osm-mesh-config namespace: kube-system resourceVersion: "2494" uid: 6c4d67f3-c241-4aeb-bf4f-b029b08faa31 spec: certificate: serviceCertValidityDuration: 24h featureFlags: enableEgressPolicy: true enableMulticlusterMode: false enableWASMStats: true observability: enableDebugServer: true osmLogLevel: info tracing: address: jaeger.osm-system.svc.cluster.local enable: false endpoint: /api/v2/spans port: 9411 sidecar: configResyncInterval: 0s enablePrivilegedInitContainer: false envoyImage: mcr.azk8s.cn/oss/envoyproxy/envoy:v1.18.3 initContainerImage: mcr.azk8s.cn/oss/openservicemesh/init:v0.9.1 logLevel: error maxDataPlaneConnections: 0 resources: {} traffic: enableEgress: true enablePermissiveTrafficPolicyMode: true inboundExternalAuthorization: enable: false failureModeAllow: false statPrefix: inboundExtAuthz timeout: 1s useHTTPSIngress: false
请注意
enablePermissiveTrafficPolicyMode
配置为true
。 在 OSM 中,宽松流量策略模式会绕过 SMI 流量策略强制执行。 在此模式下,OSM 将自动发现作为服务网格一部分的服务。 将在每个 Envoy 代理分支上为发现的服务编写流量策略规则,以允许在这些服务之间通信。警告
在继续操作之前,请验证宽松流量策略模式是否设置为
true
。 如果不是,请使用以下命令将其更改为true
:kubectl patch meshconfig osm-mesh-config -n kube-system -p '{"spec":{"traffic":{"enablePermissiveTrafficPolicyMode":true}}}' --type=merge
如果不再需要 Azure 资源,请使
az group delete
命令删除部署的测试资源组:az group delete --name osm-bicep-test
或者,可以从群集中卸载 OSM 加载项和相关资源。 有关详细信息,请参阅从 AKS 群集卸载 Open Service Mesh 加载项。
本文介绍了如何在 AKS 群集上安装 OSM 加载项,并验证它是否已安装且正在运行。 使用群集上安装的 OSM 插件,你可以部署示例应用程序或载入现有应用程序以使用你的 OSM 网格。