在 Azure Kubernetes 服务(AKS)中安装 Linkerd

Linkerd 是一个开源服务网格,并且是 CNCF 孵化项目。 Linkerd 是一个超级轻型服务网格,提供包括流量管理、服务标识和安全性、可靠性和可观测性在内的功能。 有关 Linkerd 的详细信息,请参阅官方 Linkerd 常见问题解答Linkerd 体系结构 文档。

本文介绍如何安装 Linkerd。 Linkerd linkerd 客户端二进制文件安装在客户端计算机上,Linkerd 组件安装在 AKS 上的 Kubernetes 群集中。

注释

这些说明引用 Linkerd 版本 stable-2.6.0

Linkerd stable-2.6.x 可以与 Kubernetes 版本 1.13+兼容运行。 可以在 GitHub - Linkerd 版本中找到其他稳定版本和边缘 Linkerd 版本。

在这篇文章中,你将学会如何:

  • 下载并安装 Linkerd 客户端二进制
  • 在 AKS 上安装 Linkerd
  • 验证 Linkerd 安装
  • 访问仪表板
  • 从 AKS 卸载 Linkerd

在您开始之前

假设您已创建 AKS 集群(Kubernetes 1.13及以上版本,并已启用 Kubernetes RBAC),并已与集群建立 kubectl 连接。 如果需要有关其中任何项的帮助,请参阅 AKS 快速入门

所有 Linkerd Pod 都必须计划为在 Linux 节点上运行 - 此设置是下面详述的安装方法中的默认设置,无需其他配置。

本文将 Linkerd 安装指南分为几个离散步骤。 结果与官方 Linkerd 入门 指南的结构相同。

下载并安装 Linkerd 客户端二进制文件

在基于 Bash 的 Linux 或 适用于 Linux 的 Windows 子系统的 Shell 中,使用 curl 下载 Linkerd 版本,操作如下:

# Specify the Linkerd version that will be leveraged throughout these instructions
LINKERD_VERSION=stable-2.6.0

curl -sLO "https://github.com/linkerd/linkerd2/releases/download/$LINKERD_VERSION/linkerd2-cli-$LINKERD_VERSION-linux"

客户端 linkerd 二进制文件在客户端计算机上运行,并允许与 Linkerd 服务网格进行交互。 使用以下命令在 Linux 或linkerd的基于 bash 的 shell 中安装 Linkerd 客户端二进制文件。 这些命令可将 linkerd 客户端二进制文件复制到 PATH 中的标准用户程序位置。

sudo cp ./linkerd2-cli-$LINKERD_VERSION-linux /usr/local/bin/linkerd
sudo chmod +x /usr/local/bin/linkerd

如果要为 Linkerd linkerd 客户端二进制文件完成命令行,请按如下所示进行设置:

# Generate the bash completion file and source it in your current shell
mkdir -p ~/completions && linkerd completion bash > ~/completions/linkerd.bash
source ~/completions/linkerd.bash

# Source the bash completion file in your .bashrc so that the command-line completions
# are permanently available in your shell
echo "source ~/completions/linkerd.bash" >> ~/.bashrc

下载并安装 Linkerd 客户端二进制文件

在 MacOS 上的 bash shell 中使用 curl 来下载 Linkerd 版本,如下所示:

# Specify the Linkerd version that will be leveraged throughout these instructions
LINKERD_VERSION=stable-2.6.0

curl -sLO "https://github.com/linkerd/linkerd2/releases/download/$LINKERD_VERSION/linkerd2-cli-$LINKERD_VERSION-darwin"

客户端 linkerd 二进制文件在客户端计算机上运行,并允许与 Linkerd 服务网格进行交互。 使用以下命令在 MacOS 上的基于 bash 的 shell 中安装 Linkerd linkerd 客户端二进制文件。 这些命令可将 linkerd 客户端二进制文件复制到 PATH 中的标准用户程序位置。

sudo cp ./linkerd2-cli-$LINKERD_VERSION-darwin /usr/local/bin/linkerd
sudo chmod +x /usr/local/bin/linkerd

如果要为 Linkerd linkerd 客户端二进制文件设置命令行补全功能,请按如下所示进行配置:

# Generate the bash completion file and source it in your current shell
mkdir -p ~/completions && linkerd completion bash > ~/completions/linkerd.bash
source ~/completions/linkerd.bash

# Source the bash completion file in your .bashrc so that the command-line completions
# are permanently available in your shell
echo "source ~/completions/linkerd.bash" >> ~/.bashrc

下载并安装 Linkerd 链接器客户端二进制文件

在 Windows 的 PowerShell 环境中,使用 Invoke-WebRequest 如下下载 Linkerd 发行版:

# Specify the Linkerd version that will be leveraged throughout these instructions
$LINKERD_VERSION="stable-2.6.0"

# Enforce TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = "tls12"
$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -URI "https://github.com/linkerd/linkerd2/releases/download/$LINKERD_VERSION/linkerd2-cli-$LINKERD_VERSION-windows.exe" -OutFile "linkerd2-cli-$LINKERD_VERSION-windows.exe"

客户端 linkerd 二进制文件在客户端计算机上运行,并允许与 Linkerd 服务网格进行交互。 使用以下命令在 Windows 上基于 PowerShell 的 shell 中安装 Linkerd linkerd 客户端二进制文件。 这些命令将 linkerd 客户端二进制文件复制到 Linkerd 文件夹,并通过 PATH 使其立即在当前 shell 中可用,并且在 shell 重启后也可永久使用。 不需要提升的(管理员)特权即可运行这些命令,不需重启 shell。

# Copy linkerd.exe to C:\Linkerd
New-Item -ItemType Directory -Force -Path "C:\Linkerd"
Copy-Item -Path ".\linkerd2-cli-$LINKERD_VERSION-windows.exe" -Destination "C:\Linkerd\linkerd.exe"

# Add C:\Linkerd to PATH. 
# Make the new PATH permanently available for the current User
$USER_PATH = [environment]::GetEnvironmentVariable("PATH", "User") + ";C:\Linkerd\"
[environment]::SetEnvironmentVariable("PATH", $USER_PATH, "User")
# Make the new PATH immediately available in the current shell
$env:PATH += ";C:\Linkerd\"

在 AKS 上安装 Linkerd

在安装 Linkerd 之前,我们将运行预安装检查,以确定是否可以在 AKS 群集上安装控制平面:

linkerd check --pre

应会看到如下所示的内容,指示 AKS 群集是 Linkerd 的有效安装目标:

kubernetes-api
--------------
√ can initialize the client
√ can query the Kubernetes API

kubernetes-version
------------------
√ is running the minimum Kubernetes API version
√ is running the minimum kubectl version

pre-kubernetes-setup
--------------------
√ control plane namespace does not already exist
√ can create Namespaces
√ can create ClusterRoles
√ can create ClusterRoleBindings
√ can create CustomResourceDefinitions
√ can create PodSecurityPolicies
√ can create ServiceAccounts
√ can create Services
√ can create Deployments
√ can create CronJobs
√ can create ConfigMaps
√ no clock skew detected

pre-kubernetes-capability
-------------------------
√ has NET_ADMIN capability
√ has NET_RAW capability

pre-linkerd-global-resources
----------------------------
√ no ClusterRoles exist
√ no ClusterRoleBindings exist
√ no CustomResourceDefinitions exist
√ no MutatingWebhookConfigurations exist
√ no ValidatingWebhookConfigurations exist
√ no PodSecurityPolicies exist

linkerd-version
---------------
√ can determine the latest version
√ cli is up-to-date

Status check results are √

现在是时候安装 Linkerd 组件了。 使用 linkerdkubectl 二进制文件将 Linkerd 组件安装到 AKS 群集。 linkerd将自动创建命名空间,组件将安装到此命名空间中。

linkerd install | kubectl apply -f -

Linkerd 部署多个对象。 你将从上述命令的 linkerd install 输出中看到列表。 链接器组件的部署大约需要 1 分钟才能完成,具体取决于群集环境。

此时,已将 Linkerd 部署到 AKS 群集。 为了确保成功部署 Linkerd,让我们转到下一部分来 验证 Linkerd 安装

验证 Linkerd 安装

确认已成功创建资源。 使用 kubectl get svckubectl get pod 命令查询 linkerd 命名空间,其中 Linkerd 组件由 linkerd install 命令安装:

kubectl get svc --namespace linkerd --output wide
kubectl get pod --namespace linkerd --output wide

以下示例输出显示了应当正在运行的服务和 Pod(安排在 Linux 节点上):

NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE  SELECTOR
linkerd-controller-api   ClusterIP   10.0.110.67    <none>        8085/TCP            66s  linkerd.io/control-plane-component=controller
linkerd-destination      ClusterIP   10.0.224.29    <none>        8086/TCP            66s  linkerd.io/control-plane-component=controller
linkerd-dst              ClusterIP   10.0.225.148   <none>        8086/TCP            66s  linkerd.io/control-plane-component=destination
linkerd-grafana          ClusterIP   10.0.61.124    <none>        3000/TCP            65s  linkerd.io/control-plane-component=grafana
linkerd-identity         ClusterIP   10.0.6.104     <none>        8080/TCP            67s  linkerd.io/control-plane-component=identity
linkerd-prometheus       ClusterIP   10.0.27.168    <none>        9090/TCP            65s  linkerd.io/control-plane-component=prometheus
linkerd-proxy-injector   ClusterIP   10.0.100.133   <none>        443/TCP             64s  linkerd.io/control-plane-component=proxy-injector
linkerd-sp-validator     ClusterIP   10.0.221.5     <none>        443/TCP             64s  linkerd.io/control-plane-component=sp-validator
linkerd-tap              ClusterIP   10.0.18.14     <none>        8088/TCP,443/TCP    64s  linkerd.io/control-plane-component=tap
linkerd-web              ClusterIP   10.0.37.108    <none>        8084/TCP,9994/TCP   66s  linkerd.io/control-plane-component=web

NAME                                      READY   STATUS    RESTARTS   AGE   IP            NODE                            NOMINATED NODE   READINESS GATES
linkerd-controller-66ddc9f94f-cm9kt       3/3     Running   0          66s   10.240.0.50   aks-linux-16165125-vmss000001   <none>           <none>
linkerd-destination-c94bc454-qpkng        2/2     Running   0          66s   10.240.0.78   aks-linux-16165125-vmss000002   <none>           <none>
linkerd-grafana-6868fdcb66-4cmq2          2/2     Running   0          65s   10.240.0.69   aks-linux-16165125-vmss000002   <none>           <none>
linkerd-identity-74d8df4b85-tqq8f         2/2     Running   0          66s   10.240.0.48   aks-linux-16165125-vmss000001   <none>           <none>
linkerd-prometheus-699587cf8-k8ghg        2/2     Running   0          65s   10.240.0.41   aks-linux-16165125-vmss000001   <none>           <none>
linkerd-proxy-injector-6556447f64-n29wr   2/2     Running   0          64s   10.240.0.32   aks-linux-16165125-vmss000000   <none>           <none>
linkerd-sp-validator-56745cd567-v4x7h     2/2     Running   0          64s   10.240.0.6    aks-linux-16165125-vmss000000   <none>           <none>
linkerd-tap-5cd9fc566-ct988               2/2     Running   0          64s   10.240.0.15   aks-linux-16165125-vmss000000   <none>           <none>
linkerd-web-774c79b6d5-dhhwf              2/2     Running   0          65s   10.240.0.70   aks-linux-16165125-vmss000002   <none>           <none>

Linkerd 通过 linkerd 客户端二进制文件提供命令,用于验证 Linkerd 控制平面是否已成功安装和配置。

linkerd check

应会看到如下所示的内容,指示安装成功:

kubernetes-api
--------------
√ can initialize the client
√ can query the Kubernetes API

kubernetes-version
------------------
√ is running the minimum Kubernetes API version
√ is running the minimum kubectl version

linkerd-config
--------------
√ control plane Namespace exists
√ control plane ClusterRoles exist
√ control plane ClusterRoleBindings exist
√ control plane ServiceAccounts exist
√ control plane CustomResourceDefinitions exist
√ control plane MutatingWebhookConfigurations exist
√ control plane ValidatingWebhookConfigurations exist
√ control plane PodSecurityPolicies exist

linkerd-existence
-----------------
√ 'linkerd-config' config map exists
√ heartbeat ServiceAccount exist
√ control plane replica sets are ready
√ no unschedulable pods
√ controller pod is running
√ can initialize the client
√ can query the control plane API

linkerd-api
-----------
√ control plane pods are ready
√ control plane self-check
√ [kubernetes] control plane can talk to Kubernetes
√ [prometheus] control plane can talk to Prometheus
√ no invalid service profiles

linkerd-version
---------------
√ can determine the latest version
√ cli is up-to-date

control-plane-version
---------------------
√ control plane is up-to-date
√ control plane and cli versions match

Status check results are √

访问仪表板

Linkerd 附带了一个仪表盘,提供有关服务网格和工作负载的见解。 若要访问仪表板,请使用 linkerd dashboard 命令。 此命令利用 kubectl 端口转发 在客户端计算机与 AKS 群集中的相关 Pod 之间建立安全连接。 然后,它会在默认浏览器中自动打开仪表板。

linkerd dashboard

该命令还将创建端口转发并返回 Grafana 仪表板的链接。

Linkerd dashboard available at:
http://127.0.0.1:50750
Grafana dashboard available at:
http://127.0.0.1:50750/grafana
Opening Linkerd dashboard in the default browser

从 AKS 卸载 Linkerd

警告

从正在运行的系统中删除 Linkerd 可能会导致服务之间的流量相关问题。 确保在继续之前,您的系统能够在没有 Linkerd 的情况下正常运行。

首先,需要删除数据平面代理。 从工作负荷命名空间中删除任何自动代理注入 注释,并部署工作负荷。 工作负荷不应再具有任何关联的数据平面组件。

最后,删除控制平面,如下所示:

linkerd install --ignore-cluster | kubectl delete -f -

后续步骤

若要了解 Linkerd 的更多安装和配置选项,请参阅以下官方 Linkerd 指南:

您还可以通过以下方式遵循其他场景: