Using kubernetes argoproj.io with awx.ansible.com
TypeScriptTo leverage Kubernetes with Argo CD (
argoproj.io
) and AWX (awx.ansible.com
) using Pulumi, we can create a multi-step process that involves setting up a Kubernetes cluster, installing Argo CD, and then setting up AWX.Setting up Kubernetes Cluster: Firstly, we need a Kubernetes cluster where all our workloads will run. Let's create a cluster using Azure's AKS service, as it is a managed Kubernetes service which simplifies the cluster deployment and management.
Installing Argo CD: Once we have a Kubernetes cluster, we can install Argo CD, a declarative, GitOps continuous delivery tool for Kubernetes. Argo CD allows developers to define applications using Kubernetes manifests, which can be stored in version control systems.
Setting up AWX: AWX is the open-source version of Ansible Tower. AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is an upstream project to Ansible Tower, so it gives you the freedom to automate the provisioning of the infrastructure that's required for your applications.
In the following program, we will go through these steps using Pulumi and TypeScript:
- Provision an AKS cluster using the
azure-native
package. - Deploy Argo CD onto the AKS cluster using the
kubernetes
package. - Set up AWX as a workload within the cluster. Typically, AWX deployment would be done using an
awx-operator
which is a Kubernetes Operator; however, this would require more complex custom resource definitions (CRDs) and out-of-scope for a beginner-oriented deployment, so we'll stick to deploying AWX through standard Kubernetes manifests.
Here is how you could provision and set up these components using Pulumi:
import * as azure from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create an Azure Resource Group const resourceGroup = new azure.resources.ResourceGroup("resourceGroup"); // Create an AKS cluster const cluster = new azure.containerservice.ManagedCluster("aksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, vmSize: "Standard_DS2_v2", name: "agentpool" }], dnsPrefix: "aks-argocd-awx", linuxProfile: { adminUsername: "aksuser", ssh: { publicKeys: [{ keyData: "your-public-key-here", // Replace with your ssh public key }], }, }, }); const creds = pulumi.all([cluster.name, resourceGroup.name]).apply(([name, rg]) => azure.containerservice.listManagedClusterUserCredentials({ resourceName: name, resourceGroupName: rg, })); const encodedKubeconfig = pulumi.secret(creds).kubeconfigs[0].value; const kubeconfig = encodedKubeconfig.apply(enc => Buffer.from(enc, 'base64').toString()); // Set up a Kubernetes provider instance using the kubeconfig const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Deploy Argo CD using a Kubernetes provider const argocdNamespace = new k8s.core.v1.Namespace("argocdNamespace", { metadata: { name: "argocd" } }, { provider: k8sProvider }); const argocdManifests = new k8s.yaml.ConfigGroup("argocdManifests", { files: ["https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml"], }, { provider: k8sProvider, dependsOn: argocdNamespace }); // Deploy AWX (This should ideally be done using the AWX operator but simplified here for the demo) const awxNamespace = new k8s.core.v1.Namespace("awxNamespace", { metadata: { name: "awx" } }, { provider: k8sProvider }); const awxManifests = new k8s.yaml.ConfigGroup("awxManifests", { files: ["https://raw.githubusercontent.com/ansible/awx-operator/devel/deploy/awx-operator.yaml"], }, { provider: k8sProvider, dependsOn: awxNamespace }); export const aksClusterName = cluster.name; export const argocdServerHostname = argocdManifests.getResource("v1/Service", "argocdNamespace", "argocd-server").status.loadBalancer.ingress[0].hostname; export const kubeconfigOutput = encodedKubeconfig;
In the above program:
resourceGroup
is being created for organizing all our Azure resources.cluster
sets up an AKS cluster within the resource group.creds
fetches the AKS cluster credentials, which includes the kubeconfig needed to interact with the cluster.k8sProvider
establishes a Kubernetes provider to manage Kubernetes resources.argocdNamespace
andargocdManifests
deploy Argo CD to the cluster into its own namespace.awxNamespace
andawxManifests
deploy AWX using its operator's manifest. We use the operator's manifest directly from the AWX GitHub repository.
After running this Pulumi program, you would have an AKS cluster running with Argo CD and AWX installed. You can use the output variables such as
argocdServerHostname
to access Argo CD's server andkubeconfigOutput
to interact with your Kubernetes cluster usingkubectl
.- Provision an AKS cluster using the