Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[terraform] #874: terraform module for AWS #942

Merged
merged 37 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
989a7f7
[terraform] Limit google_kubernetes_storage_class to the module becau…
barroco Jan 24, 2023
da1bb1d
[terraform] Initial AWS terraform dependency
barroco Jan 25, 2023
029d6cb
[terraform] terraform-aws-kubernetes variables
barroco Jan 25, 2023
2dcc233
[terraform] add aws_route53_zone_id variable
barroco Jan 26, 2023
db72ce3
[terraform] terraform-aws-kubernetes: Load Balancer
barroco Jan 26, 2023
1c27d3f
[terraform] terraform-aws-kubernetes: Documentation WIP
barroco Jan 27, 2023
260fdfb
[terraform] terraform-aws-kubernetes: Limit the deployment to a singl…
barroco Jan 27, 2023
6e02411
[tanka] Update tanka manifests to support multiple cloud providers
barroco Jan 27, 2023
c33c897
[terraform] terraform-commons-dss: Add new cloud provider field to ta…
barroco Jan 27, 2023
d472b6c
[terraform-aws-dss] Update scripts to support arn format for cluster …
barroco Jan 30, 2023
0308656
[tanka] Add AWS resources
barroco Jan 30, 2023
eaca312
[terraform-aws-kubernetes] Elastic Block storage configuration
barroco Jan 30, 2023
19b3a8d
[terraform-aws-dss] Add variables subnet and cert_name
barroco Jan 30, 2023
865da83
[terraform] fix authorization description.
barroco Jan 30, 2023
d0f7f48
[terraform-aws-dss] Add new module
barroco Jan 30, 2023
12155e2
[terraform-aws-dss] Propagate subnet to tanka and use tf to provision…
barroco Jan 30, 2023
a658bb3
Delete inappropriate file
barroco Jan 30, 2023
b307c62
[terraform-aws-dss] Fix gcp missing service and certname variable
barroco Jan 30, 2023
86c9c53
[terraform-aws-dss] Finalize DNS setup for CRDB and documentation
barroco Jan 30, 2023
1d591c7
Format
barroco Jan 30, 2023
a98017f
[terraform-aws-kubernetes] Rename AWSLoadBalancerControllerPolicy res…
barroco Jan 30, 2023
715feda
Clean up
barroco Jan 30, 2023
5b70f79
[terraform-aws-kubernetes] Handle manual dns setup
barroco Jan 30, 2023
1bcab61
[terraform-aws-kubernetes] Remove unused data
barroco Jan 30, 2023
6d44621
[terraform-aws-kubernetes] Disable useless verification stage for man…
barroco Jan 30, 2023
695e252
Address PR comments
barroco Jan 31, 2023
cfa8777
Address PR comments
barroco Jan 31, 2023
2123736
Indent
barroco Jan 31, 2023
e5509a9
[terraform] Fix variables generator to bring back global variables
barroco Jan 31, 2023
e884a79
Address PR comment
barroco Jan 31, 2023
1588bc5
Add README to /deploy
barroco Feb 8, 2023
20a3b28
Update authorization description
barroco Feb 8, 2023
aba1ddb
Improve DNS documentation
barroco Feb 8, 2023
2802f93
Fix tk delete
barroco Feb 8, 2023
c1a0eee
Fix static name to prevent conflicts with multiple deployments
barroco Feb 8, 2023
6c0bbdf
Add as default tags the cluster name
barroco Feb 8, 2023
c1f6fe4
small refactoring
barroco Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed build/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ endpoint.
like `gcr.io/your-project-id` (do not include the image name;
it will be appended by the build script)

- For Amazon Web Services, `DOCKER_URL` should be set similarly to as described
[here](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html),
like `${aws_account_id}.dkr.ecr.${region}.amazonaws.com/` (do not include the image name;
it will be appended by the build script)

1. Ensure you are logged into your docker registry service.

- For Google Cloud,
Expand All @@ -89,6 +94,10 @@ endpoint.
Ensure that
[appropriate permissions are enabled](https://cloud.google.com/container-registry/docs/access-control).

- For Amazon Web Services, create a private repository by following the instructions
[here](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html), then login
as described [here](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html).

1. Use the [`build.sh` script](./build.sh) in this directory to build and push
an image tagged with the current date and git commit hash.

Expand Down
11 changes: 7 additions & 4 deletions build/apply-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ set -x
CONTEXT="$1"
DIR="$(pwd)"
NAMESPACE="$2"
CLIENTS_CERTS_DIR="$DIR/workspace/$CONTEXT/client_certs_dir"
NODE_CERTS_DIR="$DIR/workspace/$CONTEXT/node_certs_dir"
CA_KEY_DIR="$DIR/workspace/$CONTEXT/ca_key_dir"
CA_CRT_DIR="$DIR/workspace/$CONTEXT/ca_certs_dir"

# Replace characters breaking folder names
WORKSPACE=$(echo "${CONTEXT}" | tr ':/' '_')
CLIENTS_CERTS_DIR="$DIR/workspace/$WORKSPACE/client_certs_dir"
NODE_CERTS_DIR="$DIR/workspace/$WORKSPACE/node_certs_dir"
CA_KEY_DIR="$DIR/workspace/$WORKSPACE/ca_key_dir"
CA_CRT_DIR="$DIR/workspace/$WORKSPACE/ca_certs_dir"
JWT_PUBLIC_CERTS_DIR="$DIR/jwt-public-certs"
UPLOAD_CA_KEY=true

Expand Down
27 changes: 27 additions & 0 deletions build/deploy/base.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,31 @@ local util = import 'util.libsonnet';

assert std.length(self.containers) > 0 : 'must have at least one container',
},

// Reusable cloud provider specific resources
AWSLoadBalancer(metadata, name, ipNames, subnet): $.Service(metadata, name) {
type:: 'LoadBalancer',
metadata+: {
annotations+: {
'service.beta.kubernetes.io/aws-load-balancer-type': 'external',
'service.beta.kubernetes.io/aws-load-balancer-nlb-target-type': 'ip',
'service.beta.kubernetes.io/aws-load-balancer-scheme': 'internet-facing',
'service.beta.kubernetes.io/aws-load-balancer-eip-allocations': std.join(',', ipNames),
'service.beta.kubernetes.io/aws-load-balancer-name': name,
'service.beta.kubernetes.io/aws-load-balancer-subnets': metadata.subnet,
},
},
spec+: {
loadBalancerClass: "service.k8s.aws/nlb",
},
},

AWSLoadBalancerWithManagedCert(metadata, name, ipNames, subnet, certARN): $.AWSLoadBalancer(metadata, name, ipNames, subnet) {
metadata+: {
annotations+: {
'service.beta.kubernetes.io/aws-load-balancer-ssl-ports': '443',
'service.beta.kubernetes.io/aws-load-balancer-ssl-cert': certARN,
},
},
}
}
11 changes: 10 additions & 1 deletion build/deploy/cockroachdb-auxiliary.libsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local base = import 'base.libsonnet';
local volumes = import 'volumes.libsonnet';

local cockroachLB(metadata, name, ip) = base.Service(metadata, name) {
local googleCockroachLB(metadata, name, ip) = base.Service(metadata, name) {
port:: metadata.cockroach.grpc_port,
app:: 'cockroachdb',
spec+: {
Expand All @@ -10,6 +10,15 @@ local cockroachLB(metadata, name, ip) = base.Service(metadata, name) {
},
};

local awsCockroachLB(metadata, name, ip) = base.AWSLoadBalancer(metadata, name, [ip], metadata.subnet) {
port:: metadata.cockroach.grpc_port,
app:: 'cockroachdb',
};

local cockroachLB(metadata, name, ip) =
if metadata.cloud_provider == "google" then googleCockroachLB(metadata, name, ip)
else if metadata.cloud_provider == "aws" then awsCockroachLB(metadata, name, ip);

{
all(metadata): {
CockroachInit: if metadata.cockroach.shouldInit then base.Job(metadata, 'init') {
Expand Down
71 changes: 46 additions & 25 deletions build/deploy/core-service.libsonnet
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
local base = import 'base.libsonnet';
local volumes = import 'volumes.libsonnet';

local ingress(metadata) = base.Ingress(metadata, 'https-ingress') {
metadata+: {
annotations: {
'kubernetes.io/ingress.global-static-ip-name': metadata.backend.ipName,
'kubernetes.io/ingress.allow-http': 'false',
local awsLoadBalancer(metadata) = base.AWSLoadBalancerWithManagedCert(metadata, 'gateway', [metadata.backend.ipName], metadata.subnet, metadata.backend.certName) {
app:: 'core-service',
spec+: {
ports: [{
port: 443,
targetPort: metadata.backend.port,
protocol: "TCP",
name: "http",
}]
}
};

{
GoogleIngress(metadata): base.Ingress(metadata, 'https-ingress') {
metadata+: {
annotations: {
'kubernetes.io/ingress.global-static-ip-name': metadata.backend.ipName,
'kubernetes.io/ingress.allow-http': 'false',
},
},
},
spec: {
defaultBackend: {
service: {
name: 'core-service',
port: {
number: metadata.backend.port,
spec: {
defaultBackend: {
service: {
name: 'core-service',
port: {
number: metadata.backend.port,
}
}
}
},
},
},
};

{
ManagedCertIngress(metadata): {
ingress: ingress(metadata) {
GoogleManagedCertIngress(metadata): {
ingress: $.GoogleIngress(metadata) {
metadata+: {
annotations+: {
'networking.gke.io/managed-certificates': 'https-certificate',
Expand All @@ -38,22 +50,31 @@ local ingress(metadata) = base.Ingress(metadata, 'https-ingress') {
},
},

PresharedCertIngress(metadata, certName): ingress(metadata) {
GooglePresharedCertIngress(metadata, certName): $.GoogleIngress(metadata) {
metadata+: {
annotations+: {
'ingress.gcp.kubernetes.io/pre-shared-cert': certName,
},
},
},

all(metadata): {
ingress: $.ManagedCertIngress(metadata),
service: base.Service(metadata, 'core-service') {
app:: 'core-service',
port:: metadata.backend.port,
type:: 'NodePort',
enable_monitoring:: false,
GoogleService(metadata): base.Service(metadata, 'core-service') {
app:: 'core-service',
port:: metadata.backend.port,
type:: 'NodePort',
enable_monitoring:: false,
},

CloudNetwork(metadata): {
google: if metadata.cloud_provider == "google" then {
ingress: $.GoogleManagedCertIngress(metadata),
service: $.GoogleService(metadata),
},
aws_loadbalancer: if metadata.cloud_provider == "aws" then awsLoadBalancer(metadata)
},

all(metadata): {
network: $.CloudNetwork(metadata),

deployment: base.Deployment(metadata, 'core-service') {
apiVersion: 'apps/v1',
Expand Down
7 changes: 5 additions & 2 deletions build/deploy/metadata_base.libsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
cloud_provider: 'google', // Either google or aws
namespace: error 'must supply namespace',
clusterName: error 'must supply cluster name',
enable_istio: false,
Expand All @@ -15,7 +16,7 @@
grpc_port: 26257,
http_port: 8080,
image: 'cockroachdb/cockroach:v21.2.7',
nodeIPs: error 'must supply the per-node ip addresses as an array',
nodeIPs: error 'must supply the per-node ip addresses as an array', // For AWS, this array should contain the allocation id of the elastic ips.
JoinExisting: [],
storageClass: 'standard',
},
Expand All @@ -24,7 +25,7 @@
roleBinding: false,
},
backend: {
ipName: error 'must supply ip name',
ipName: error 'must supply ip name', // For AWS, use the elastic ip allocation id.
port: 8080,
image: error 'must specify image',
prof_grpc_name: '',
Expand All @@ -33,6 +34,7 @@
jwksKeyIds: [],
hostname: error 'must specify hostname',
dumpRequests: false,
certName: if $.cloud_provider == "aws" then error 'must specify certName for AWS cloud provider', # Only used by AWS
},
alert: {
enable: false,
Expand All @@ -56,4 +58,5 @@
custom_rules: [], // An array of Prometheus recording rules, each of which is an object with "record" and "expr" properties.
custom_args: [], // An array of strings to pass as commandline arguments to Prometheus.
},
subnet: if $.cloud_provider == "aws" then error 'must specify subnet for AWS cloud provider', // For AWS, subnet of the elastic ips
}
7 changes: 6 additions & 1 deletion build/make-certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ def namespace(self):

@property
def directory(self):
return os.path.join('workspace', self._cluster_context)
# Replace characters breaking folder names
def remove_special_chars(s: str):
for c in [":", "/"]:
s = s.replace(c, "_")
return s
return os.path.join('workspace', remove_special_chars(self._cluster_context))

@property
def ca_certs_file(self):
Expand Down
11 changes: 11 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# DSS Deployment

**Work in progress**

This folder contains the increments toward the new deployment approach as described in [#874](https://github.com/interuss/dss/issues/874).

The infrastructure folder contains the terraform modules to deploy the DSS to kubernetes clusters of various cloud providers:

- Amazon Web Services: [terraform-aws-dss](./infrastructure/modules/terraform-aws-dss/README.md)
- Google Cloud Engine: [terraform-google-dss](./infrastructure/modules/terraform-google-dss/README.md)

1 change: 1 addition & 0 deletions deploy/infrastructure/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
terraform.tfstate
terraform.tfstate.backup
personal/
*.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-app.yml
Loading