1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# Running Development Environment in Kubernetes
## Start Minikube
If you do not already have Minikube, install it from:
https://minikube.sigs.k8s.io/docs/start/
Note: This environment has only been tested on Linux.
```
$ minikube start \
--mount \
--mount-string="/path/to/awx:/awx_devel" \
--cpus=4 \
--memory=8g \
--addons=ingress
```
### Verify
Ensure that your AWX source code is properly mounted inside of the minikube node:
```
$ minikube ssh
$ ls -la /awx_devel
```
## Deploy the AWX Operator
Clone the [awx-operator](https://github.com/ansible/awx-operator).
For the following playbooks to work, you will need to:
```
$ pip install openshift
```
If you are not changing any code in the operator itself, git checkout the latest version from https://github.com/ansible/awx-operator/releases, and then follow the instructions in the awx-operator [README](https://github.com/ansible/awx-operator#basic-install).
If making changes to the operator itself, run the following command in the root
of the awx-operator repo. If not, continue to the next section.
### Building and Deploying a Custom AWX Operator Image
```
# in awx-operator repo on the branch you want to use
$ export IMAGE_TAG_BASE=quay.io/<username>/awx-operator
$ export VERSION=<custom-tag>
$ make docker-build
$ docker push ${IMAGE_TAG_BASE}:${VERSION}
```
## Deploy AWX into Minikube using the AWX Operator
If have have not made any changes to the AWX Dockerfile, run the following
command. If you need to test out changes to the Dockerfile, see the
"Custom AWX Development Image for Kubernetes" section below.
In the root of awx-operator:
```
$ ansible-playbook ansible/instantiate-awx-deployment.yml \
-e development_mode=yes \
-e image=ghcr.io/ansible/awx_kube_devel \
-e image_version=devel \
-e image_pull_policy=Always \
-e service_type=nodeport \
-e namespace=$NAMESPACE
```
Check the operator with the following commands:
```
# Check the operator deployment
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
awx 1/1 1 1 16h
awx-operator-controller-manager 1/1 1 1 16h
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
awx-operator-controller-manager-b775bfc7c-fn995 2/2 Running 0 16h
```
If there are errors in the image pull, check that it is using the right tag. You can update the tag that it will pull by editing the deployment.
### Custom AWX Development Image for Kubernetes
I have found `minikube cache add` to be unacceptably slow for larger images such
as this. A faster workflow involves building the image and pushing it to a
registry:
In the root of the AWX repo:
```
$ make awx-kube-dev-build
$ docker push ghcr.io/ansible/awx_kube_devel:${COMPOSE_TAG}
```
In the root of awx-operator:
```
$ ansible-playbook ansible/instantiate-awx-deployment.yml \
-e development_mode=yes \
-e image=ghcr.io/ansible/awx_kube_devel \
-e image_version=${COMPOSE_TAG} \
-e image_pull_policy=Always \
-e service_type=nodeport \
-e namespace=$NAMESPACE
```
To iterate on changes to the Dockerfile, rebuild and push the image, then delete
the AWX Pod. A new Pod will respawn with the latest revision.
## Accessing AWX
To access via the web browser, run the following command:
```
$ minikube service awx-service --url
```
To retrieve your admin password
```
$ kubectl get secrets awx-admin-password -o json | jq '.data.password' | xargs | base64 -d
```
To tail logs from the containers
```
# Find the awx pod name
kubectl get pods
NAME READY STATUS RESTARTS AGE
awx-56fbfbb6c8-jkhzl 4/4 Running 0 13h
awx-operator-controller-manager-b775bfc7c-fn995 2/2 Running 0 16h
awx-postgres-0 1/1 Running 0 16h
# now you know the pod name, tail logs from task container in pod
kubectl logs -f awx-56fbfbb6c8-jkhzl -n awx -c awx-task
# alternatively, or in a different window tail logs from the web container in pod
kubectl logs -f awx-56fbfbb6c8-jkhzl -n awx -c awx-web
```
To exec in to the container:
```
# Using same pod name we found above from "kubectl get pods"
$ kubectl exec -it awx-56fbfbb6c8-k6p82 -c awx-task bash
```
The application will live reload when files are edited just like in the development environment. Just like in the development environment, if the application totally crashes because files are invalid syntax or other fatal problem, you will get an error like "no python application" in the web container. Delete the whole control plane pod and wait until a new one spins up automatically.
```
$ kubectl delete pod awx-56fbfbb6c8-k6p82
```
|