基于 K3s 使用 awx-operator 部署 ansible awx

Ansible管理平臺AWX的部署 https://www.sujx.net/2023/09/17/Kubernetes-K3s/index.html
(含 docker.io品嚣,gcr.io,registry.k8s.io mirror 配置)

一钧大、K3S 環(huán)境

mirror 加速配置

cat > /etc/rancher/k3s/registries.yaml <<EOF
mirrors:
  docker.io:
    endpoint:
      - "https://registry.cn-hangzhou.aliyuncs.com/"
  quay.io:
    endpoint:
      - "https://quay.tencentcloudcr.com/"
  registry.k8s.io:
    endpoint:
      - "https://registry.aliyuncs.com/v2/google_containers"
  gcr.io:
    endpoint:
      - "https://gcr.m.daocloud.io/"
  k8s.gcr.io:
    endpoint:
      - "https://registry.aliyuncs.com/google_containers"
  ghcr.io:
    endpoint:
      - "https://ghcr.m.daocloud.io/"
EOF

二、源碼準(zhǔn)備

[root@VM-201-12-centos ~]# git clone https://github.com/ansible/awx-operator.git
[root@VM-201-12-centos ~]# cd awx-operator/
[root@VM-201-12-centos awx-operator]# git branch
* devel
[root@VM-201-12-centos awx-operator]# git checkout tags/2.12.2
Note: switching to 'tags/2.12.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 630a5ee Fix bug where uppercase Route fails (#1731)

[root@VM-201-12-centos awx-operator]# git branch
* (HEAD detached at 2.12.2)
  devel

可以使用 git tag 查看所有 tag 信息

三啊央、部署 awx-operator

[root@VM-201-12-centos awx-operator]# make deploy
namespace/awx created
customresourcedefinition.apiextensions.k8s.io/awxbackups.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxmeshingresses.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
[root@VM-201-12-centos awx-operator]# kubectl get pods --namespace awx
NAME                                               READY   STATUS    RESTARTS   AGE
awx-operator-controller-manager-589cdd869b-k57p4   2/2     Running   0          139m
[root@VM-201-12-centos awx-operator]# kubectl config set-context --current --namespace=awx
Context "default" modified.

[root@VM-201-12-centos awx-operator]# kubectl get pods
NAME                                               READY   STATUS    RESTARTS   AGE
awx-operator-controller-manager-589cdd869b-k57p4   2/2     Running   0          140m

四涨醋、默認(rèn)部署 (awx-demo)

在同目錄創(chuàng)建文件 awx-demo.yml(默認(rèn)有的),如下:

---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
  name: awx-demo
spec:
  service_type: nodeport

自定義需要添加到文件 kustomization.yaml浴骂,如下

...
resources:
  - github.com/ansible/awx-operator/config/default?ref=<tag>
  # Add this extra line:
  - awx-demo.yml
...

部署

[root@VM-201-12-centos awx-operator]# kubectl apply -k .
error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/root/awx-operator'

創(chuàng)建 kustomization.yaml 如下

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=2.12.2
  # Add this extra line:
  - awx-demo.yml

# Set the image tags to match the git version from above
images:
  - name: quay.io/ansible/awx-operator
    newTag: 2.12.2

# Specify a custom namespace in which to install AWX
namespace: awx
[root@VM-201-12-centos awx-operator]# kubectl apply -k .
...
awx.awx.ansible.com/awx-demo created

慢慢等

[root@VM-201-12-centos ~]# kubectl get pods
NAME                                               READY   STATUS    RESTARTS        AGE
awx-demo-postgres-13-0                             1/1     Running   0               4h48m
awx-demo-task-6bd48c549d-rcdbm                     4/4     Running   0               4h47m
awx-demo-web-869bf8d66d-swc82                      3/3     Running   0               4h45m
awx-operator-controller-manager-589cdd869b-k57p4   2/2     Running   1 (4h38m ago)   7h15m

[root@VM-201-12-centos ~]# kubectl get pods -l "app.kubernetes.io/managed-by=awx-operator"
NAME                             READY   STATUS    RESTARTS   AGE
awx-demo-postgres-13-0           1/1     Running   0          4h50m
awx-demo-task-6bd48c549d-rcdbm   4/4     Running   0          4h49m
awx-demo-web-869bf8d66d-swc82    3/3     Running   0          4h46m

[root@VM-201-12-centos ~]# kubectl get svc -l "app.kubernetes.io/managed-by=awx-operator"
NAME                   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
awx-demo-postgres-13   ClusterIP   None           <none>        5432/TCP       4h50m
awx-demo-service       NodePort    10.43.125.17   <none>        80:31664/TCP   4h49m

五、自定義部署 (外聯(lián)pgsql)

1. 創(chuàng)建 pgsql

CREATE USER awx WITH PASSWORD 'awx';
CREATE DATABASE awx OWNER awx;

2. 創(chuàng)建 pgsql 的 secret

pg-secret.yaml 如下

---
apiVersion: v1
kind: Secret
metadata:
  name: sitawx-postgres-configuration
  namespace: awx
stringData:
  host: "10.41.98.124"
  port: "5432"
  database: awx
  username: awx
  password: awx
  sslmode: prefer
  type: unmanaged
type: Opaque
[root@VM-201-31-centos awx-operator]# kubectl apply -f pg-secret.yaml 
secret/sitawx-postgres-configuration created
[root@VM-201-31-centos awx-operator]# 
[root@VM-201-31-centos awx-operator]# kubectl get secrets
NAME                            TYPE     DATA   AGE
sitawx-postgres-configuration   Opaque   7      10s

3. 創(chuàng)建 aws-sit.yaml

---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
  name: awx-sit
spec:
  service_type: nodeport
  postgres_configuration_secret: sitawx-postgres-configuration

4. 修改 kustomization.yaml

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=2.15.0
  - ./config/default
  # Add this extra line:
  - awx-sit.yml

# Set the image tags to match the git version from above
images:
  - name: quay.io/ansible/awx-operator
    newTag: 2.15.0

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

5. 部署 awx

[root@VM-201-31-centos awx-operator]# kubectl apply -k .
namespace/awx unchanged
...
awx.awx.ansible.com/awx-sit created
[root@VM-201-31-centos awx-operator]# kubectl get pods
NAME                                              READY   STATUS      RESTARTS   AGE
awx-operator-controller-manager-9874d5cfc-hhqql   2/2     Running     0          26m
awx-sit-web-869b5fcbb8-96ts9                      3/3     Running     0          16m
awx-sit-migration-24.2.0-hjt6h                    0/1     Completed   0          16m
awx-sit-task-dd9dcb5fc-d6kwb                      4/4     Running     0          16m

六溯警、卸載

[root@VM-201-31-centos awx-operator]# kubectl delete awx awx-sit
awx.awx.ansible.com "awx-sit" deleted

[root@VM-201-31-centos awx-operator]# kubectl get pods
NAME                                              READY   STATUS        RESTARTS   AGE
awx-operator-controller-manager-9874d5cfc-7kj5s   2/2     Running       0          89m
awx-sit-web-75895b8f88-84cd4                      3/3     Terminating   0          58m
...
[root@VM-201-31-centos awx-operator]# kubectl get pods
NAME                                              READY   STATUS    RESTARTS   AGE
awx-operator-controller-manager-9874d5cfc-7kj5s   2/2     Running   0          90m

[root@VM-201-31-centos awx-operator]# kubectl get deployments
NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
awx-operator-controller-manager   1/1     1            1           90m

七坎炼、訪問

獲取密碼

[root@VM-201-12-centos ~]# kubectl get secret awx-demo-admin-password -o jsonpath="{.data.password}" | base64 --decode ; echo
Z4SEZLrZnDqjsHpWJqfNQYF7b6llT1Tp
[root@VM-201-31-centos awx-operator]# kubectl get service
NAME                                              TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
awx-operator-controller-manager-metrics-service   ClusterIP   10.43.73.225   <none>        8443/TCP       36m
awx-sit-service                                   NodePort    10.43.7.169    <none>        80:30791/TCP   26m

URL
http://k3s_worknode_ip:port

k3s_worknode_ip 為 POD 所在 node ip
port 通過 kubectl get service 查找愧膀,如上為 30791

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末谣光,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子芬为,更是在濱河造成了極大的恐慌萄金,老刑警劉巖媚朦,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件氧敢,死亡現(xiàn)場離奇詭異询张,居然都是意外死亡孙乖,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門唯袄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人蜗帜,你說我怎么就攤上這事恋拷√保” “怎么了蔬顾?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵湘捎,是天一觀的道長诀豁。 經(jīng)常有香客問我,道長窥妇,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任秩伞,我火速辦了婚禮欺矫,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘展氓。我一直安慰自己穆趴,他們只是感情好遇汞,可當(dāng)我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布未妹。 她就那樣靜靜地躺著,像睡著了一般络它。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上歪赢,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天,我揣著相機與錄音埋凯,去河邊找鬼点楼。 笑死,一個胖子當(dāng)著我的面吹牛掠廓,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播甩恼,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼条摸!你這毒婦竟也來了悦污?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤塞关,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后子巾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡线梗,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年椰于,在試婚紗的時候發(fā)現(xiàn)自己被綠了仪搔。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片瘾婿。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出抢呆,到底是詐尸還是另有隱情,我是刑警寧澤笛谦,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站饥脑,受9級特大地震影響恳邀,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜谣沸,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望笋颤。 院中可真熱鬧乳附,春花似錦椰弊、人聲如沸许溅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽茬祷。三九已至清焕,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間秸妥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工沃粗, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人最盅。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓突雪,卻偏偏與公主長得像,于是被迫代替她去往敵國和親涡贱。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內(nèi)容