快速部署AWX至k8s上,这是一个非常基础的部署,请根据您的具体需求去查看相应的官方文档。

基础环境

  • RockyLinux 9.1
  • k3s
    部署时有一个google镜像可能需要您自行下载并导入。

安装Kubernetes

快速安装单节点的k3s。

1
2
3
4
curl -sfL https://get.k3s.io | sh -

# 国内用户请使用以下方法加速安装:
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -

验证安装

1
2
3
4
5
6
7
8
9
10
$ kubectl get pods -A

NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system local-path-provisioner-79f67d76f8-7qnmp 1/1 Running 0 78s
kube-system coredns-597584b69b-t5rzs 1/1 Running 0 78s
kube-system helm-install-traefik-crd-lxgwd 0/1 Completed 0 78s
kube-system helm-install-traefik-h98hh 0/1 Completed 1 78s
kube-system metrics-server-5f9f776df5-wjftg 1/1 Running 0 78s
kube-system svclb-traefik-a4e4ab03-bz7mb 2/2 Running 0 37s
kube-system traefik-66c46d954f-rs8jl 1/1 Running 0 37s

安装AWX

AWX-oprator官方Github仓库地址:https://github.com/ansible/awx-operator

安装Git(必需)

1
dnf install git -y

安装kustomize

1
2
3
4
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash

也可以直接去Github项目中去下载相应的二进制文件:
https://github.com/kubernetes-sigs/kustomize/releases

将kustomize的二进制文件移动至/usr/local/bin/中,并赋予执行权限。

1
2
3
mv kustomize /usr/local/bin/

chmod +x /usr/local/bin/kustomize

创建kustomization.yaml文件:vim kustomization.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
# Find the latest tag here: https://github.com/ansible/awx-operator/releases
- github.com/ansible/awx-operator/config/default?ref=1.1.4 # 更改你想安装版本号。截止写文章的时候最新版本是1.2.0,但是安装报错,改为1.1.4就没问题了

# Set the image tags to match the git version from above
images:
- name: quay.io/ansible/awx-operator
newTag: 1.1.4 # 与上方保持一致即可

# Specify a custom namespace in which to install AWX
namespace: awx

运行以下命令进行初始部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ kustomize build . | kubectl apply -f -
namespace/awx created
customresourcedefinition.apiextensions.k8s.io/awxbackups.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxrestores.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxs.awx.ansible.com created
serviceaccount/awx-operator-controller-manager created
role.rbac.authorization.k8s.io/awx-operator-awx-manager-role created
role.rbac.authorization.k8s.io/awx-operator-leader-election-role created
clusterrole.rbac.authorization.k8s.io/awx-operator-metrics-reader created
clusterrole.rbac.authorization.k8s.io/awx-operator-proxy-role created
rolebinding.rbac.authorization.k8s.io/awx-operator-awx-manager-rolebinding created
rolebinding.rbac.authorization.k8s.io/awx-operator-leader-election-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/awx-operator-proxy-rolebinding created
configmap/awx-operator-awx-manager-config created
service/awx-operator-controller-manager-metrics-service created
deployment.apps/awx-operator-controller-manager created

验证部署

1
2
3
4
5
6
7
# 后续所使用的命名空间都是awx
# 这里直接部署会拉取image失败,请自行解决网络问题,或者从别的机器上导出相应的image并导入,image名称:
# gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0

$ kubectl get pods -n awx
NAME READY STATUS RESTARTS AGE
awx-operator-controller-manager-66ccd8f997-rhd4z 2/2 Running 0 11s

创建第二个yaml文件,即awx.yaml

1
2
3
4
5
6
7
---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx
spec:
service_type: nodeport

在之前创建的kustomization.yaml文件中resources里添加一行

1
2
3
4
5
6
...
resources:
- github.com/ansible/awx-operator/config/default?ref=1.1.4
# 添加以下一行:
- awx.yaml
...

再次运行kustomize创建AWX instance。这个过程需要持续几分钟,快慢取决于你所使用的机器资源配置

1
kustomize build . | kubectl apply -f -

可以通过命令查看部署进度

1
kubectl logs -f deployments/awx-operator-controller-manager -c awx-manager -n awx

创建完成后,最终将看到以下信息:

1
2
3
4
5
6
7
8
9

----- Ansible Task Status Event StdOut (awx.ansible.com/v1beta1, Kind=AWX, awx/awx) -----


PLAY RECAP *********************************************************************
localhost : ok=75 changed=0 unreachable=0 failed=0 skipped=71 rescued=0 ignored=1


----------

获取登录密码

1
2
$  kubectl get secret awx-admin-password -o jsonpath="{.data.password}" -n awx | base64 --decode ; echo
t6yREMgWH9mJuegVXndRDKWdELaVcWow

打开浏览器就可以访问你的AWX了。