Deploying AWX in GKE — Part 2 (prod-ready)

Deploying AWX in GKE — Part 2 (prod-ready) In the previous post Deploying AWX on GKE, we saw how to perform a basic AWX deployment on a GKE Cluster using version 2.11.0 with Helm. Now let’s perform a production-ready deployment. We’ll be us

Source comparison and review notes
  • Automated pair-review warning (AI bilingual content review): Both originals show git clone https://github.com/ansible/awx-operator/tree/2.17.0 ..., which is a GitHub tree URL rather than a normal repository clone URL; verify the clone command before use.

In the previous post Deploying AWX on GKE, we saw how to perform a basic AWX deployment on a GKE Cluster using version 2.11.0 with Helm.

Now let’s perform a production-ready deployment. We’ll be using:

  • AWX Operator version 2.17.0.
  • AWX 24.4.0 release.
  • Persistent storage (standard-rwo) in GKE.

We’ll be fixing:

  1. Ingress bug in GKE.
  2. AccessType bug in PV of Task and Web Pods.
  3. Access permissions bug for writing data to the PVC for the Postgres pod.

Clone Repository

First, we must download the latest available release of the Operator. As of the date of this post, the latest release available is 2.17.0. To do this, we will run the following commands:

Bash
git clone https://github.com/ansible/awx-operator/tree/2.17.0 awx-operator.2.17.0
cd ./awx-operator.2.17.0/
git checkout tags/2.17.0 -b release-2.17.0
code .

This will ensure that we have the files available to the release version.

Edit Ingress Jinja Template

Based on this Issue from the Official AWX Operator Repository:

  • Within the roles, enter the installer role.
  • In the templates section, go to Networking and select the ingress.yaml.j2 file.
  • Path: ./roles/installer/templates/networking/ingress.yaml.j2
  • Replace line 30 of that file with the following code:
Plain text
- path: '{{ (ingress_path + '/*').replace("//","/") }}'

This step ensures that the manifest generated by the K8s Ingress Operator (HTTPs Load Balancer in GKE) has a correct Path.

Create Custom Operator Container

Next, we need to create and store our custom image of the Operator in a private Artifact Registry.

Create GCP Artifact Registry

We’ll run the following gcloud command to create an Artifact Registry in GCP to save our image:

Bash
gcloud artifacts repositories create awx_repo \
--repository-format=docker \
--location=us-east4 --description="AWX Containers Repo" \
--project=multicloudstech-gke

Authenticate Docker with gcloud to push the images to this repo:

Bash
gcloud auth configure-docker us-east4-docker.pkg.dev

Docker Build

Now we’ll build our own AWX-Operator Docker image. After modifying the Jinja2 File of the Ingress, perform the Docker Build:

Bash
docker build -t us-east4-docker.pkg.dev/multicloudstech-gke/awx-repo/awx-operator:2.17.0 . --no-cache

Verify the constructed image:

Docker Push

Push the created image to our artifact registry:

Bash
docker push us-east4-docker.pkg.dev/multicloudstech-gke/awx-repo/awx-operator:2.17.0

Verify that the image was successfully pushed:

Configure AWX Artifact Registry Login

Assign the necessary permissions to our Kubernetes nodes’ service account to read/pull images from the Artifact Registry. Assign the Artifact Registry Reader role to the Service Account assigned to the GKE nodes.

Create AWX Operator YAML

Using Make, we’ll create the AWX Operator Manifesto. Run the following command (on Linux):

Plain text
make gen-resources | tee awx-operator.yaml

The file will be created to display our Operator:

Changes to the Operator’s YAML

Make some changes to our manifesto.

Image Pull Secret

On line 2860, comment out the Image Pull Secret line.

Replace the default image of the Operator on line 2832 with the new one we just created.

Deploy AWX Operator

Apply the initial manifest of the Operator:

Bash
kubectl apply -f ./awx-operator.yaml -n awx

Verify that all resources related to the Namespace, CRDs, RBAC permissions, K8s Service Accounts, ConfigMaps, Operator Service, and Deployment are created.

Now we can see that our Operator is deployed:

Deploy AWX Resource

With our Operator deployed and running, we can deploy AWX. First, a prerequisite…

Prerequisite

Ensure:

  • HTTPs Load Balancing is enabled in GKE.
  • A static IP reserved for ingress.
  • Have a certificate to configure in the ingress.

Create Secret for the Certificate

We have a certificate created with Let’s Encrypt. Let’s store it as a secret in Kubernetes:

Bash
kubectl create secret tls awx-multiclouds-tech-cert --cert=C:\Users\Matthew\AppData\Local\Posh-ACME\LE_PROD\1629371947\awx.multiclouds.tech\cert.cer --key=C:\Users\Matthew\AppData\Local\Posh-ACME\LE_PROD\1629371947\awx.multiclouds.tech\cert.key -n awx

Create AWX Resource Manifest

Create the following manifesto:

Plain text
---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: ansible-awx
namespace: awx
spec:
service_type: nodeport
postgres_storage_class: standard-rwo
projects_persistence: true
projects_storage_access_mode: ReadWriteOnce
ingress_type: Ingress
ingress_path: /
ingress_path_type: ImplementationSpecific
hostname: awx.multiclouds.tech
ingress_tls_secret: awx-multiclouds-tech-cert
ingress_annotations: |
kubernetes.io/ingress.global-static-ip-name: <<< IP ADDRESS NAME >>>
cloud.google.com/backend-config: '{"ports": {"80":"awx-backendconfig"}}'
service_annotations: |
cloud.google.com/backend-config: '{"ports": {"80":"awx-backendconfig"}}'
cloud.google.com/neg: '{"ingress": true}'
  • Remember to assign the name of the IP address reservation made on GCP.
  • Note: You may receive an error if you change the projects_storage_access_mode parameter.

Deploy AWX

Apply the manifest:

Bash
kubectl apply -f ./awx-deploy.yaml -n awx

Check the status of our Pods:

Bash
kubectl get pods -n awx -w

Verify the pod’s logs:

The Postgres container cannot write data to PVC:

Fix Postgres “mkdir: cannot create directory ‘/var/lib/pgsql/data/userdata’: Permission denied”

To solve this error, we must generate a temporary pod to inspect the PVC and assign permissions to user 26, which Postgres uses by default.

Create the following manifest for a PVC-Inspector pod:

YAML
apiVersion: v1
kind: Pod
metadata:
name: pvc-inspector
namespace: awx
spec:
containers:
- image: busybox
name: pvc-inspector
command: ["tail"]
args: ["-f", "/dev/null"]
volumeMounts:
- mountPath: /pvc/data/
name: pvc-mount
volumes:
- name: pvc-mount
persistentVolumeClaim:
claimName: postgres-15-ansible-awx-postgres-15-0

Apply the manifest:

Bash
kubectl apply -f ./pvc-inspector.yaml -n awx

Enter the pod:

Bash
kubectl exec -it pvc-inspector -n awx -- /bin/sh

Assign the following permission:

Plain text
chown -R 26:26 /pvc/data/

This should cause the Postgres pod to switch to the “Running” state. If it doesn’t do it automatically, delete it and it will be recreated thanks to the autohealing of our deployment.

Then the deployment will continue until all the pods are working:

Troubleshooting Ingress

The ingress is not working properly since the HTTP Load Balancer we’ve been waiting for in GCP is being created:

Using the kubectl describe command, we can see the error thrown:

Bash
kubectl describe ingress ansible-awx-ingress -n awx

To fix this, we will create the BackendConfig:

YAML
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
name: awx-backendconfig
namespace: awx

Apply the backend-config file:

Bash
kubectl apply -f ./backend-config.yaml -n awx

This will ensure an HTTPs Load Balancer is created in GCP:

After a moment, Kubernetes notices the change and makes the correct configuration of Ingress:

Now we can properly enter our Cluster 🙂

Mateo Di Loreto


If you like what i do and want to support my content you can Buy Me a Coffe

Thanks for reading. The learning continues in the next article.