2023-06-21 09:09:26 +08:00
|
|
|
|
[#]: subject: "How to Install Ansible AWX on Kubernetes Cluster"
|
|
|
|
|
[#]: via: "https://www.linuxtechi.com/install-ansible-awx-on-kubernetes-cluster/"
|
|
|
|
|
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
|
|
|
|
[#]: collector: "lkxed"
|
|
|
|
|
[#]: translator: "geekpi"
|
2023-06-25 17:34:40 +08:00
|
|
|
|
[#]: reviewer: "wxy"
|
|
|
|
|
[#]: publisher: "wxy"
|
|
|
|
|
[#]: url: "https://linux.cn/article-15941-1.html"
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
如何在 Kubernetes 集群上安装 Ansible AWX
|
|
|
|
|
======
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
![][0]
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
> 在本文中,我们将逐步向你展示如何在 Kubernetes(k8s)集群上安装 Ansible AWX。
|
|
|
|
|
|
|
|
|
|
Ansible AWX 是一个强大的开源工具,用于管理和自动化 IT 基础设施。AWX 为 Ansible 提供图形用户界面,使你可以轻松创建、安排和运行 Ansible <ruby>剧本<rt>Playbook</rt></ruby>。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
另一方面,Kubernetes 是一种流行的容器编排平台,广泛用于部署和管理容器化应用。
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
先决条件:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
- Kubernetes 集群
|
|
|
|
|
- Kubectl
|
|
|
|
|
- 具有 sudo 权限和集群管理员权限的普通用户
|
|
|
|
|
- 互联网连接
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
### 步骤 1:安装 Helm
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
如果你的系统上安装了 Helm,则在命令下运行以进行安装,
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
|
|
|
|
$ chmod +x get_helm.sh
|
|
|
|
|
$ ./get_helm.sh
|
|
|
|
|
$ helm version
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![Install-helm-linux-command-line][1]
|
|
|
|
|
|
|
|
|
|
### 步骤 2:安装 AWX chart
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
在 Kubernetes 上安装 AWX 的最简单方法是使用 AWX Helm “<ruby>海图<rt>chart</rt></ruby>”。因此,要通过 “海图” 安装 AWX,首先使用以下 `helm` 命令添加仓库。(LCTT 译注:Kubernetes 生态中大量使用了和航海有关的比喻,因此本文在翻译时也采用了这些比喻)
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ helm repo add awx-operator https://ansible.github.io/awx-operator/
|
|
|
|
|
"awx-operator" has been added to your repositories
|
|
|
|
|
$
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:如果你之前已经添加过此仓库,请在命令下运行以获取最新版本的软件包。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ helm repo update
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
要通过 Helm 安装 awx-operator,请运行:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ helm install ansible-awx-operator awx-operator/awx-operator -n awx --create-namespace
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![helm-install-awx-operator-kubernetes][2]
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
这将下载 AWX 海图并将其安装在 `awx` 命名空间中的 Kubernetes 集群上。安装过程可能需要几分钟,请耐心等待。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
### 步骤 3:验证 AWX 操作员安装
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
安装成功后,你可以通过运行以下命令来验证 AWX <ruby>操作员<rt>operator</rt></ruby> 状态:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo kubectl get pods -n awx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
你应该看到这样的东西:
|
|
|
|
|
|
|
|
|
|
![awx-operator-pod-status-kubectl][3]
|
|
|
|
|
|
|
|
|
|
### 步骤 4: 创建 PV、PVC 并部署 AWX yaml 文件
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
AWX 需要 postgres <ruby>容器荚<rt>pod</rt></ruby> 的持久卷。那么,让我们首先为本地卷创建一个存储类。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
注意:在本文中,我使用本地文件系统作为持久卷。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ vi local-storage-class.yaml
|
|
|
|
|
apiVersion: storage.k8s.io/v1
|
|
|
|
|
kind: StorageClass
|
|
|
|
|
metadata:
|
|
|
|
|
name: local-storage
|
|
|
|
|
namespace: awxprovisioner: kubernetes.io/no-provisioner
|
|
|
|
|
volumeBindingMode: WaitForFirstConsumer
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
保存并关闭文件,然后运行:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl create -f local-storage-class.yaml
|
|
|
|
|
$ kubectl get sc -n awx
|
|
|
|
|
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION
|
|
|
|
|
local-storage kubernetes.io/no-provisioner Delete WaitForFirstConsumer false
|
|
|
|
|
$
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
接下来使用以下 `pv.yaml` 文件创建持久卷(PV):
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ vi pv.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: PersistentVolume
|
|
|
|
|
metadata:
|
|
|
|
|
name: postgres-pv
|
|
|
|
|
namespace: awx
|
|
|
|
|
spec:
|
|
|
|
|
capacity:
|
|
|
|
|
storage: 10Gi
|
|
|
|
|
volumeMode: Filesystem
|
|
|
|
|
accessModes:
|
|
|
|
|
- ReadWriteOnce
|
|
|
|
|
persistentVolumeReclaimPolicy: Delete
|
|
|
|
|
storageClassName: local-storage
|
|
|
|
|
local:
|
|
|
|
|
path: /mnt/storage
|
|
|
|
|
nodeAffinity:
|
|
|
|
|
required:
|
|
|
|
|
nodeSelectorTerms:
|
|
|
|
|
- matchExpressions:
|
|
|
|
|
- key: kubernetes.io/hostname
|
|
|
|
|
operator: In
|
|
|
|
|
values:
|
|
|
|
|
- k8s-worker
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
保存并退出文件。
|
|
|
|
|
|
|
|
|
|
![Postgres-pv-awx-kubernetes][4]
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
重要说明:确保文件夹 `/mnt/storage` 存在于工作节点上,如果不存在,则在工作节点上使用 `mkdir` 命令创建它。在我们的例子中,工作节点是 `k8s-worker`。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
执行下面的命令在 `awx` 命名空间中创建 `postgres-pv`。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl create -f pv.yaml
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
成功创建 PV 后,使用 `pvc.yaml` 文件创建 PersistentVolumeClaim:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ vi pvc.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: PersistentVolumeClaim
|
|
|
|
|
metadata:
|
|
|
|
|
name: postgres-13-ansible-awx-postgres-13-0
|
|
|
|
|
namespace: awx
|
|
|
|
|
spec:
|
|
|
|
|
storageClassName: local-storage
|
|
|
|
|
accessModes:
|
|
|
|
|
- ReadWriteOnce
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
storage: 10Gi
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![posgres-pvc-awx-kubernetes][5]
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
要创建 PVC,请运行以下 `kubectl` 命令:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl create -f pvc.yaml
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
使用下面的命令验证 PV 和 PVC 的状态:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl get pv,pvc -n awx
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
现在,我们都准备好部署 AWX 实例了。创建一个包含以下内容的 `ansible-awx.yaml` 文件:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ vi ansible-awx.yaml
|
|
|
|
|
---
|
|
|
|
|
apiVersion: awx.ansible.com/v1beta1
|
|
|
|
|
kind: AWX
|
|
|
|
|
metadata:
|
|
|
|
|
name: ansible-awx
|
|
|
|
|
namespace: awx
|
|
|
|
|
spec:
|
|
|
|
|
service_type: nodeport
|
|
|
|
|
postgres_storage_class: local-storage
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![Ansible-awx-yaml-file][6]
|
|
|
|
|
|
|
|
|
|
保存并关闭文件。
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
执行以下 `kubectl` 命令来部署 awx 实例:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl create -f ansible-awx.yaml
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
等待几分钟,然后检查 `awx` 命名空间中的容器荚状态。
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl get pods -n awx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![Ansible-AWX-Pods-Status-Kubernetes][7]
|
|
|
|
|
|
|
|
|
|
### 步骤 5:访问 AWX Web 界面
|
|
|
|
|
|
|
|
|
|
要访问 AWX Web 界面,你需要创建一个公开 awx-web 部署的服务:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl expose deployment ansible-awx-web --name ansible-awx-web-svc --type NodePort -n awx
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
此命令将创建一个 `NodePort` 服务,该服务将 AWX Web 容器的端口映射到 Kubernetes 节点上的端口。你可以通过运行以下命令找到端口号:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl get svc ansible-awx-web-svc -n awx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
这将输出如下内容:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
|
ansible-awx-web-svc NodePort 10.99.83.248 <none> 8052:32254/TCP 82s
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在此示例中,Web 服务在端口 32254 上可用。
|
|
|
|
|
|
|
|
|
|
![Expose-Ansible-AWX-Web-NodePort-Kubernetes][8]
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
默认情况下,admin 用户是 Web 界面的 `admin`,密码在 `<resourcename>-admin-password` 机密信息中。要检索管理员密码,请运行:
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl get secrets -n awx | grep -i admin-password
|
|
|
|
|
ansible-awx-admin-password Opaque 1 109m
|
|
|
|
|
$
|
|
|
|
|
$ kubectl get secret ansible-awx-admin-password -o jsonpath="{.data.password}" -n awx | base64 --decode ; echo
|
|
|
|
|
l9mWcIOXQhSKnzZQyQQ9LZf3awDV0YMJ
|
|
|
|
|
$
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
你现在可以打开 Web 浏览器并进入 `http://<node-ip>:<node-port>/` 来访问 AWX Web 界面。在上面的示例中,URL 是:
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
```
|
2023-06-21 09:09:26 +08:00
|
|
|
|
http://192.168.1.223:3225
|
2023-06-25 17:34:40 +08:00
|
|
|
|
```
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
![AWX-Login-URL-Kubernetes][9]
|
|
|
|
|
|
|
|
|
|
输入凭据后单击登录。
|
|
|
|
|
|
|
|
|
|
![Ansible-AWX-Web-Dashboard][10]
|
|
|
|
|
|
|
|
|
|
恭喜! 你已在 Kubernetes 上成功安装 Ansible AWX。你现在可以使用 AWX 来自动化你的 IT 基础架构,并让你作为系统管理员的生活更轻松。
|
|
|
|
|
|
2023-06-25 17:34:40 +08:00
|
|
|
|
*(题图:MJ/bfd354aa-2ee5-4555-98b8-ac5207cbeabe)*
|
|
|
|
|
|
2023-06-21 09:09:26 +08:00
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.linuxtechi.com/install-ansible-awx-on-kubernetes-cluster/
|
|
|
|
|
|
|
|
|
|
作者:[Pradeep Kumar][a]
|
|
|
|
|
选题:[lkxed][b]
|
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2023-06-25 17:34:40 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2023-06-21 09:09:26 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: https://www.linuxtechi.com/author/pradeep/
|
|
|
|
|
[b]: https://github.com/lkxed/
|
|
|
|
|
[1]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Install-helm-linux-command-line.png?ezimgfmt=rs%3Adevice%2Frscb22-1
|
|
|
|
|
[2]: https://www.linuxtechi.com/wp-content/uploads/2023/05/helm-install-awx-operator-kubernetes.png
|
|
|
|
|
[3]: https://www.linuxtechi.com/wp-content/uploads/2023/05/awx-operator-pod-status-kubectl.png
|
|
|
|
|
[4]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Postgres-pv-awx-kubernetes.png
|
|
|
|
|
[5]: https://www.linuxtechi.com/wp-content/uploads/2023/05/posgres-pvx-awx-kubernetes.png
|
|
|
|
|
[6]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Ansible-awx-yaml-file.png
|
|
|
|
|
[7]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Ansible-AWX-Pods-Status-Kubernetes.png
|
|
|
|
|
[8]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Expose-Ansible-AWX-Web-NodePort-Kubernetes.png
|
|
|
|
|
[9]: https://www.linuxtechi.com/wp-content/uploads/2023/05/AWX-Login-URL-Kubernetes.png
|
2023-06-25 17:34:40 +08:00
|
|
|
|
[10]: https://www.linuxtechi.com/wp-content/uploads/2023/05/Ansible-AWX-Web-Dashboard.png
|
|
|
|
|
[0]: https://img.linux.net.cn/data/attachment/album/202306/25/172630f134fo6cg5gcodu4.jpg
|