Skip to content

Commit cf43f59

Browse files
authored
new: kro lab module in Automation section (#1691)
1 parent 123e0b6 commit cf43f59

File tree

18 files changed

+1006
-0
lines changed

18 files changed

+1006
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
logmessage "Deleting resources created by kro..."
6+
7+
delete-all-if-crd-exists webapplicationdynamodbs.kro.run
8+
9+
delete-all-if-crd-exists webapplications.kro.run
10+
11+
delete-all-if-crd-exists resourcegraphdefinitions.kro.run
12+
13+
kubectl delete crd/webapplicationdynamodbs.kro.run --ignore-not-found
14+
15+
kubectl delete crd/webapplications.kro.run --ignore-not-found
16+
17+
uninstall-helm-chart kro kro-system
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- nlb.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: ui-nlb
5+
annotations:
6+
service.beta.kubernetes.io/aws-load-balancer-type: external
7+
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
8+
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance
9+
namespace: ui
10+
spec:
11+
type: LoadBalancer
12+
ports:
13+
- port: 80
14+
targetPort: 8080
15+
name: http
16+
selector:
17+
app.kubernetes.io/name: ui
18+
app.kubernetes.io/instance: ui
19+
app.kubernetes.io/component: service
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
terraform {
2+
required_providers {
3+
kubectl = {
4+
source = "gavinbunney/kubectl"
5+
version = ">= 1.14"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = "us-east-1"
12+
alias = "virginia"
13+
}
14+
15+
data "aws_caller_identity" "current" {}
16+
data "aws_region" "current" {}
17+
18+
data "aws_ecrpublic_authorization_token" "token" {
19+
provider = aws.virginia
20+
}
21+
22+
23+
module "eks_blueprints_addons" {
24+
source = "aws-ia/eks-blueprints-addons/aws"
25+
version = "1.22.0"
26+
27+
enable_aws_load_balancer_controller = true
28+
aws_load_balancer_controller = {
29+
wait = true
30+
role_name = "${var.addon_context.eks_cluster_id}-alb-controller"
31+
policy_name = "${var.addon_context.eks_cluster_id}-alb-controller"
32+
}
33+
34+
cluster_name = var.addon_context.eks_cluster_id
35+
cluster_endpoint = var.addon_context.aws_eks_cluster_endpoint
36+
cluster_version = var.eks_cluster_version
37+
oidc_provider_arn = var.addon_context.eks_oidc_provider_arn
38+
39+
eks_addons = {
40+
eks-pod-identity-agent = {
41+
addon_version = "v1.1.0-eksbuild.1"
42+
}
43+
}
44+
45+
observability_tag = null
46+
}
47+
48+
resource "time_sleep" "blueprints_addons_sleep" {
49+
depends_on = [
50+
module.eks_blueprints_addons
51+
]
52+
53+
create_duration = "15s"
54+
destroy_duration = "15s"
55+
}
56+
57+
resource "kubernetes_manifest" "ui_alb" {
58+
depends_on = [time_sleep.blueprints_addons_sleep]
59+
60+
manifest = {
61+
"apiVersion" = "networking.k8s.io/v1"
62+
"kind" = "Ingress"
63+
"metadata" = {
64+
"name" = "ui"
65+
"namespace" = "ui"
66+
"annotations" = {
67+
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
68+
"alb.ingress.kubernetes.io/target-type" = "ip"
69+
"alb.ingress.kubernetes.io/healthcheck-path" = "/actuator/health/liveness"
70+
}
71+
}
72+
"spec" = {
73+
ingressClassName = "alb",
74+
"rules" = [{
75+
"http" = {
76+
paths = [{
77+
path = "/"
78+
pathType = "Prefix"
79+
"backend" = {
80+
service = {
81+
name = "ui"
82+
port = {
83+
number = 80
84+
}
85+
}
86+
}
87+
}]
88+
}
89+
}]
90+
}
91+
}
92+
}
93+
94+
module "eks_ack_addons" {
95+
source = "aws-ia/eks-ack-addons/aws"
96+
97+
# Cluster Info
98+
cluster_name = var.addon_context.eks_cluster_id
99+
cluster_endpoint = var.addon_context.aws_eks_cluster_endpoint
100+
oidc_provider_arn = var.addon_context.eks_oidc_provider_arn
101+
102+
# ECR Credentials
103+
ecrpublic_username = data.aws_ecrpublic_authorization_token.token.user_name
104+
ecrpublic_token = data.aws_ecrpublic_authorization_token.token.password
105+
106+
# Controllers to enable
107+
enable_dynamodb = true
108+
enable_iam = true
109+
enable_eks = true
110+
dynamodb = {
111+
wait = true
112+
role_name = "${var.addon_context.eks_cluster_id}-ack-dynamo"
113+
policy_name = "${var.addon_context.eks_cluster_id}-ack-dynamo"
114+
}
115+
116+
iam = {
117+
wait = true
118+
role_name = "${var.addon_context.eks_cluster_id}-ack-iam"
119+
policy_name = "${var.addon_context.eks_cluster_id}-ack-iam"
120+
}
121+
122+
eks = {
123+
wait = true
124+
role_name = "${var.addon_context.eks_cluster_id}-ack-eks"
125+
policy_name = "${var.addon_context.eks_cluster_id}-ack-eks"
126+
}
127+
128+
tags = var.tags
129+
130+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output "environment_variables" {
2+
description = "Environment variables to be added to the IDE shell"
3+
value = {
4+
DYNAMO_ACK_VERSION = var.dynamo_ack_version,
5+
KRO_VERSION = var.kro_version,
6+
ACCOUNT_ID = data.aws_caller_identity.current.account_id
7+
}
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: ui-nlb
5+
annotations:
6+
service.beta.kubernetes.io/aws-load-balancer-type: external
7+
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
8+
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance
9+
namespace: ui
10+
spec:
11+
type: LoadBalancer
12+
ports:
13+
- port: 80
14+
targetPort: 8080
15+
name: http
16+
selector:
17+
app.kubernetes.io/name: ui
18+
app.kubernetes.io/instance: ui
19+
app.kubernetes.io/component: service
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# tflint-ignore: terraform_unused_declarations
2+
variable "eks_cluster_id" {
3+
description = "EKS cluster name"
4+
type = string
5+
}
6+
7+
# tflint-ignore: terraform_unused_declarations
8+
variable "eks_cluster_version" {
9+
description = "EKS cluster version"
10+
type = string
11+
}
12+
13+
# tflint-ignore: terraform_unused_declarations
14+
variable "cluster_security_group_id" {
15+
description = "EKS cluster security group ID"
16+
type = any
17+
}
18+
19+
# tflint-ignore: terraform_unused_declarations
20+
variable "addon_context" {
21+
description = "Addon context that can be passed directly to blueprints addon modules"
22+
type = any
23+
}
24+
25+
# tflint-ignore: terraform_unused_declarations
26+
variable "tags" {
27+
description = "Tags to apply to AWS resources"
28+
type = any
29+
}
30+
31+
# tflint-ignore: terraform_unused_declarations
32+
variable "resources_precreated" {
33+
description = "Have expensive resources been created already"
34+
type = bool
35+
}
36+
37+
variable "dynamo_ack_version" {
38+
description = "The version of Dynamo ACK to use"
39+
type = string
40+
# renovate: datasource=github-releases depName=aws-controllers-k8s/dynamodb-controller
41+
default = "1.5.2"
42+
}
43+
44+
variable "kro_version" {
45+
description = "The version of Kro to use"
46+
type = string
47+
# renovate: datasource=github-releases depName=kro-run/kro
48+
default = "0.4.1"
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: kro.run/v1alpha1
2+
kind: WebApplicationDynamoDB
3+
metadata:
4+
name: carts
5+
namespace: carts
6+
spec:
7+
# Basic types
8+
appName: carts
9+
replicas: 1
10+
image: "public.ecr.aws/aws-containers/retail-store-sample-cart:1.2.1"
11+
port: 8080
12+
13+
dynamodb:
14+
tableName: "eks-workshop-carts-kro"
15+
16+
env:
17+
RETAIL_CART_PERSISTENCE_PROVIDER: "dynamodb"
18+
RETAIL_CART_PERSISTENCE_DYNAMODB_TABLE_NAME: "eks-workshop-carts-kro"
19+
20+
aws:
21+
accountID: ${AWS_ACCOUNT_ID}
22+
region: ${AWS_REGION}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: kro.run/v1alpha1
2+
kind: WebApplication
3+
metadata:
4+
name: carts
5+
namespace: carts
6+
spec:
7+
# Basic types
8+
appName: carts
9+
replicas: 1
10+
image: "public.ecr.aws/aws-containers/retail-store-sample-cart:1.2.1"
11+
port: 8080
12+
env:
13+
RETAIL_CART_PERSISTENCE_PROVIDER: "in-memory"
14+
RETAIL_CART_PERSISTENCE_DYNAMODB_TABLE_NAME: "Items"
15+
RETAIL_CART_PERSISTENCE_DYNAMODB_CREATE_TABLE: "false"
16+
17+
service:
18+
enabled: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- carts-ddb.yaml

0 commit comments

Comments
 (0)