|
| 1 | +# Dogs vs Cats Voting App |
| 2 | + |
| 3 | +A multi-tier voting application demonstrating Kro's resource composition capabilities with AWS services. |
| 4 | + |
| 5 | +> **Note**: This example composes multiple reusable components. Each component can also be deployed independently. See the [Component Dependencies](#component-dependencies) section below. |
| 6 | +
|
| 7 | +## Architecture |
| 8 | + |
| 9 | +This example showcases a complete voting application composed of reusable components: |
| 10 | + |
| 11 | +- **Vote App**: Frontend for casting votes (Python/Flask) |
| 12 | +- **Result App**: Results dashboard (Node.js) |
| 13 | +- **Worker App**: Processes votes from Redis to PostgreSQL (Java) |
| 14 | +- **RDS PostgreSQL**: Stores voting results |
| 15 | +- **ElastiCache Serverless**: Caches votes |
| 16 | +- **Ingress**: AWS Load Balancer Controller with ALB |
| 17 | + |
| 18 | +## Component Dependencies |
| 19 | + |
| 20 | +This example uses the following reusable components: |
| 21 | + |
| 22 | +- [../../kubernetes/dogsvscats/vote-app/](../../kubernetes/dogsvscats/vote-app/) - Vote frontend |
| 23 | +- [../../kubernetes/dogsvscats/result-app/](../../kubernetes/dogsvscats/result-app/) - Results dashboard |
| 24 | +- [../../kubernetes/dogsvscats/worker-app/](../../kubernetes/dogsvscats/worker-app/) - Vote processor |
| 25 | +- [../rds-postgres/](../rds-postgres/) - PostgreSQL database |
| 26 | +- [../elasticache-serverless/](../elasticache-serverless/) - Redis cache |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +- EKS cluster with AWS Load Balancer Controller installed |
| 31 | +- Kro installed and running |
| 32 | +- AWS ACK controllers for EC2, RDS, and ElastiCache |
| 33 | +- VPC with private subnets |
| 34 | + |
| 35 | +Following is a way to deploy EKS cluster that covers all the above prerequisites: |
| 36 | + |
| 37 | +Uses the workshop bootstrap Terraform that creates an EKS cluster (Auto Mode), KRO, ACK add-ons, and ALB Controller. |
| 38 | + |
| 39 | +```bash |
| 40 | +# Clone the workshop bootstrap and apply |
| 41 | +git clone https://github.com/aws-samples/krmops-on-eks-workshop.git |
| 42 | +cd krmops-on-eks-workshop/kro-and-ack/bootstrap/terraform |
| 43 | + |
| 44 | +# Set your variables |
| 45 | +export AWS_REGION=ap-southeast-2 |
| 46 | +export CLUSTER_NAME=agentcore-demo |
| 47 | + |
| 48 | +terraform init |
| 49 | +terraform apply -auto-approve \ |
| 50 | + -var="region=${AWS_REGION}" \ |
| 51 | + -var="cluster_name=${CLUSTER_NAME}" |
| 52 | + |
| 53 | +## Create ResourceGraphDefinitions |
| 54 | + |
| 55 | +Change directory to `examples`: |
| 56 | + |
| 57 | +``` |
| 58 | +cd examples/ |
| 59 | +``` |
| 60 | +
|
| 61 | +Apply the component RGs first: |
| 62 | +
|
| 63 | +```bash |
| 64 | +# Apply Kubernetes app components |
| 65 | +kubectl apply -f kubernetes/dogsvscats/vote-app/rg.yaml |
| 66 | +kubectl apply -f kubernetes/dogsvscats/result-app/rg.yaml |
| 67 | +kubectl apply -f kubernetes/dogsvscats/worker-app/rg.yaml |
| 68 | +
|
| 69 | +# Apply AWS infrastructure components |
| 70 | +kubectl apply -f aws/rds-postgres/rg.yaml |
| 71 | +kubectl apply -f aws/elasticache-serverless/rg.yaml |
| 72 | +``` |
| 73 | + |
| 74 | +Apply the main composed RG: |
| 75 | + |
| 76 | +```bash |
| 77 | +kubectl apply -f aws/dogsvscats-appstack/dogsvscats-rg.yaml |
| 78 | +``` |
| 79 | + |
| 80 | +Validate the RGs statuses are Active: |
| 81 | + |
| 82 | +``` |
| 83 | +kubectl get rgd |
| 84 | +``` |
| 85 | + |
| 86 | +Expected result: |
| 87 | + |
| 88 | +``` |
| 89 | +NAME APIVERSION KIND STATE AGE |
| 90 | +dogsvscats-app.kro.run v1alpha1 DogsvsCatsApp Active 1m |
| 91 | +elasticache-serverless.kro.run v1alpha1 ElastiCacheServerless Active 2m |
| 92 | +rds-postgres.kro.run v1alpha1 RDSPostgres Active 2m |
| 93 | +result-app.kro.run v1alpha1 ResultApp Active 2m |
| 94 | +vote-app.kro.run v1alpha1 VoteApp Active 2m |
| 95 | +worker-app.kro.run v1alpha1 WorkerApp Active 2m |
| 96 | +``` |
| 97 | + |
| 98 | +## Create an Instance of kind DogsvsCatsApp |
| 99 | + |
| 100 | +Create environment variables for your infrastructure: |
| 101 | + |
| 102 | +``` |
| 103 | +export WORKLOAD_NAME="dogsvscats-voting-app" |
| 104 | +export VPC_ID="vpc-xxxxxxxxx" |
| 105 | +export SUBNET_IDS='"subnet-xxxxxxxxx", "subnet-yyyyyyyyy", "subnet-zzzzzzzzz"' |
| 106 | +``` |
| 107 | + |
| 108 | +Validate the variables are populated: |
| 109 | + |
| 110 | +``` |
| 111 | +echo $WORKLOAD_NAME |
| 112 | +echo $VPC_ID |
| 113 | +echo $SUBNET_IDS |
| 114 | +``` |
| 115 | + |
| 116 | +Run the following command to replace the variables in `instance-template.yaml` and create `instance.yaml`: |
| 117 | + |
| 118 | +```shell |
| 119 | +envsubst < "dogsvscats-appstack/instance-template.yaml" > "dogsvscats-appstack/instance.yaml" |
| 120 | +``` |
| 121 | + |
| 122 | +Apply the `dogsvscats-appstack/instance.yaml`: |
| 123 | + |
| 124 | +``` |
| 125 | +kubectl apply -f dogsvscats-appstack/instance.yaml |
| 126 | +``` |
| 127 | + |
| 128 | +Validate instance status: |
| 129 | + |
| 130 | +``` |
| 131 | +kubectl get dogsvscatsapp dogsvscats-voting-app |
| 132 | +``` |
| 133 | + |
| 134 | +Expected result: |
| 135 | + |
| 136 | +``` |
| 137 | +NAME STATE SYNCED AGE |
| 138 | +dogsvscats-voting-app ACTIVE True 5m |
| 139 | +``` |
| 140 | + |
| 141 | +## Validate the app is working |
| 142 | + |
| 143 | +Get the URLs: |
| 144 | + |
| 145 | +``` |
| 146 | +kubectl get dogsvscatsapp dogsvscats-voting-app |
| 147 | +``` |
| 148 | + |
| 149 | +This will display both the Vote App and Result App URLs in the output. |
| 150 | + |
| 151 | +Navigate to the vote URL to cast votes, then check the result URL to see the results. |
| 152 | + |
| 153 | +## Clean votes for demo |
| 154 | + |
| 155 | +Reset votes between demos: |
| 156 | + |
| 157 | +```bash |
| 158 | +./dogsvscats/scripts/clean-votes.sh |
| 159 | +``` |
| 160 | + |
| 161 | +## What This Example Demonstrates |
| 162 | + |
| 163 | +1. **Component Composition**: Building complex applications from reusable components |
| 164 | +2. **Cross-namespace References**: Kubernetes components referencing AWS infrastructure |
| 165 | +3. **Status Propagation**: Passing endpoints and connection details between components |
| 166 | +4. **Conditional Resources**: Ingress resources created based on configuration |
| 167 | +5. **Multi-cloud Patterns**: Separating cloud-agnostic apps from cloud-specific infrastructure |
| 168 | + |
| 169 | +## Clean up |
| 170 | + |
| 171 | +Remove the instance: |
| 172 | + |
| 173 | +``` |
| 174 | +kubectl delete dogsvscatsapp dogsvscats-voting-app |
| 175 | +``` |
| 176 | + |
| 177 | +Remove the ResourceGraphDefinitions: |
| 178 | + |
| 179 | +```bash |
| 180 | +# Remove main composed RG |
| 181 | +kubectl delete rgd dogsvscats-app.kro.run |
| 182 | + |
| 183 | +# Remove component RGs |
| 184 | +kubectl delete rgd vote-app.kro.run result-app.kro.run worker-app.kro.run |
| 185 | +kubectl delete rgd rds-postgres.kro.run elasticache-serverless.kro.run |
| 186 | +``` |
0 commit comments