# Lab 2 -  AWX,AWX Operator Configurations & Deployments

### **Lab Objective**

In this lab we will learns how to deploy & configure AWX as a containers to K8s cluster.

### Deployment Steps

#### **Step 1: Prepare YML files for configurations.**

Basically, only three YML's file required to deploy the AWX onto our K8s cluster.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2F60pwBnL8ovCnIlNF9D0a%2Fawx%20files.png?alt=media&#x26;token=efe2a76f-3c44-423e-81f0-847a320a4ef3" alt=""><figcaption><p>Note: The YML files</p></figcaption></figure>

create <mark style="color:yellow;">`kustomization.yml`</mark> file with the following content:

```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=1.1.1 #change to any preference version

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

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

as you can see the version of AWX Operator is defined on `newTag` key as well as on the resources key.

create <mark style="color:yellow;">`awx-demo.yml`</mark> file with the following content:

```yaml
apiVersion: awx.ansible.com/v1beta1
kind: AWX
namespace: awx
metadata:
  name: awx-demo
spec:
  service_type: nodeport
  # default nodeport_port is 30080
  nodeport_port: 30000 #you may change this node port between 30000-32768
```

Here you will see minimal content definitions specified in the YML because AWX Operator has taken care the actual AWX deployment files.

#### **Step 2: Deploy the AWX Operator controller manager.**

Now, with all the k8s object config files in hand, we are going to execute it one by one,

Execute the build in <mark style="color:yellow;">kustomization.ym</mark><mark style="color:yellow;">**l**</mark>

```bash
$ kubectl apply -k .
```

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FpSJKfuo6JESe2JRG5MVZ%2F2022-12-18%2016_02_07-kustomization.yml%20-%20awx%20%5BSSH_%20192.168.1.131%5D%20-%20Visual%20Studio%20Code.png?alt=media&#x26;token=6188df9c-7d6a-4bb0-92eb-d8099a40c7ee" alt=""><figcaption><p>Objects that has been created</p></figcaption></figure>

Once executed, AWX operator will deploy the following objects on k8s.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FqpnihRCHGYo93RpZdJXg%2Fdeployments.png?alt=media&#x26;token=09345342-9dcb-47f6-a5a9-738c1700b337" alt=""><figcaption><p>Deployment object</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2Fz4YfsSDGSZnQQ4Wsralu%2Fpod.png?alt=media&#x26;token=81eec954-a9f4-4075-a1f1-ee9d3a0ba490" alt=""><figcaption><p>Pod object</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FOh5a87MePAiiy7WyhCEC%2Frs.png?alt=media&#x26;token=00a79349-77ae-4164-8bd7-674b26ab6d00" alt=""><figcaption><p>Replica Sets object</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FwYj4pjf4vjnb5eGTXsqw%2Fsvc.png?alt=media&#x26;token=fe001ccc-4826-4153-9907-81e7a5a0dd11" alt=""><figcaption><p>Services object</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FllpQCOlmMiTXEnLndXpN%2Fcm.png?alt=media&#x26;token=e1825217-bef0-4dd4-bcd1-18889382e297" alt=""><figcaption><p>ConfigMap object</p></figcaption></figure>

Ensure that all AWX controllers manager objects are up and running,

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FXHNNkHSg47uvQJThEvCe%2Fupn.png?alt=media&#x26;token=c5781a0d-3f2e-4674-b55d-fcc0d4330833" alt=""><figcaption></figcaption></figure>

#### Step 3: Deploy the AWX.

Now, this is where we want to execute our AWX deployment.&#x20;

Run<mark style="color:yellow;">`$ kubectl apply -f awx-demo.yml`</mark>

After the execution, we can see below additional objects has been created

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FRtTYdf5mrXrwabylKIzv%2Fpods%20add.png?alt=media&#x26;token=608a6454-f11c-4238-96e8-4c6ef6cc5c60" alt=""><figcaption><p>awx-demo and awx-demo-postgres pods created</p></figcaption></figure>

Notes, for the pods to get ready, it might take sometimes so we will just have to wait for a while.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2F054Clduo1v11zjFq0SKG%2FSS%20OBJECT.png?alt=media&#x26;token=d3050b8b-0a3c-423a-82af-7f3f98bc4d51" alt=""><figcaption><p>awx-demo-postgres-13 stateful sets created</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FGZk9MT2xiqwKZ0qamt4I%2Fsvc%20add.png?alt=media&#x26;token=30d1a9d7-23f4-4105-8ff9-2559c47396f4" alt=""><figcaption><p>awx-demo-service &#x26; awx-demo-postgres-13 services has been added</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FDmQ9mEQ6JUI0DjP7k7z7%2Fcm%20add.png?alt=media&#x26;token=d9eae229-eaac-4e9e-9c7a-6c073ddfe895" alt=""><figcaption><p>awx-demo-awx-configmap created</p></figcaption></figure>

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FsO4LEPv8CVVxMgFyBw8L%2Fpvc.png?alt=media&#x26;token=530f7c17-8e22-4220-a430-965166e12e46" alt=""><figcaption><p>the PVC for AWX</p></figcaption></figure>

Finally, ensure that all the required secrets has also been created during the deployment.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FEXaqDOHwhP9jfcWrHPDY%2Fsec%20cli.png?alt=media&#x26;token=a0e83290-8aa3-4bc0-8ff4-2a43f912c7c6" alt=""><figcaption><p>All the secrets </p></figcaption></figure>

**Step 4: Verify all the k8s object resources & connectivity to the service**

At this stage,  we will need to verify below resources has been created inside the `awx` namespace.

Below screenshots is from my end for your references.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FSncOaZKY96ArkGCGhRKz%2Fall%20res.png?alt=media&#x26;token=75e1486c-8616-490e-a838-e6f16f475fec" alt=""><figcaption></figcaption></figure>

**Step 5: Verify connectivity from the Service**

Now we have everythings up and running, we need to do final check and it can be done by the AWX API check.

**Run** `$ minikube service list`

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2FXVmMNGBpcSef1waTwaMR%2Fcon.png?alt=media&#x26;token=26333f38-8c6a-4061-afa5-0705b5af5ef7" alt=""><figcaption><p>Exposed service in Minikube</p></figcaption></figure>

Referring to above image, this is the URL that we will need to use to query the AWX Ping API's&#x20;

`AWX Service URL: http://192.168.39.154:30000`

To query the API, we can run

`$ curl -L -q http://192.168.39.154:30000/api/v2/ping 2>/dev/null`

or&#x20;

`$ curl -L -q $(minikube service awx-demo-service --url -n awx)/api/v2/ping 2>/dev/null`

We shall receives below response if everythings is good.

<figure><img src="https://4081356430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfpkGw9BiJgzxmKhSpJNH%2Fuploads%2Fpy1Drb6hSIFDuGNg95hF%2Fjq.png?alt=media&#x26;token=42b0b3a3-d890-4572-9787-8b3d94bd4f25" alt=""><figcaption><p>Response from the Ping API's</p></figcaption></figure>

*\~End of Lab 2 - AWX,AWX Operator Configurations & Deployments\~*

[*Continue to Lab 3 - Ingress Networking & Connectivity via Nginx*](https://learn.farizizwan.com/devops-and-devsecops/kubernetes/poc-lab/awx-ansible-tower-deployment-on-kubernetes/lab-3-ingress-networking-and-connectivity-via-nginx)
