├── files ├── cloud-config-base.yaml ├── install_k8s_worker.sh ├── install_k8s_utils.sh └── install_k8s.sh ├── examples ├── provider.tf ├── main.tf └── .terraform.lock.hcl ├── deployments ├── eck-kibana.yml ├── eck-elastic.yml ├── eck-filebeat.yml ├── eck-metricbeat.yml └── README.md ├── output.tf ├── efs.tf ├── local.tf ├── .gitignore ├── k8slb.tf ├── template.tf ├── secrets.tf ├── security.tf ├── asg.tf ├── data.tf ├── vars.tf ├── lb.tf ├── iam.tf ├── README.md └── LICENSE /files/cloud-config-base.yaml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | runcmd: 4 | - echo "Done" -------------------------------------------------------------------------------- /examples/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.AWS_REGION 3 | access_key = var.AWS_ACCESS_KEY 4 | secret_key = var.AWS_SECRET_KEY 5 | } -------------------------------------------------------------------------------- /deployments/eck-kibana.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: kibana.k8s.elastic.co/v1 3 | kind: Kibana 4 | metadata: 5 | name: k8s-eck-kibana 6 | spec: 7 | version: 8.8.2 8 | count: 1 9 | elasticsearchRef: 10 | name: k8s-eck -------------------------------------------------------------------------------- /output.tf: -------------------------------------------------------------------------------- 1 | output "k8s_dns_name" { 2 | value = var.create_extlb ? aws_lb.external_lb.*.dns_name : [] 3 | } 4 | 5 | output "k8s_server_private_ips" { 6 | value = data.aws_instances.k8s_servers.*.private_ips 7 | } 8 | 9 | output "k8s_workers_private_ips" { 10 | value = data.aws_instances.k8s_workers.*.private_ips 11 | } -------------------------------------------------------------------------------- /deployments/eck-elastic.yml: -------------------------------------------------------------------------------- 1 | apiVersion: elasticsearch.k8s.elastic.co/v1 2 | kind: Elasticsearch 3 | metadata: 4 | name: k8s-eck 5 | spec: 6 | version: 8.8.2 7 | nodeSets: 8 | - name: default 9 | count: 3 10 | config: 11 | node.store.allow_mmap: false 12 | volumeClaimTemplates: 13 | - metadata: 14 | name: elasticsearch-data # Do not change this name unless you set up a volume mount for the data path. 15 | spec: 16 | accessModes: 17 | - ReadWriteOnce 18 | resources: 19 | requests: 20 | storage: 20Gi 21 | storageClassName: efs-eck-sc -------------------------------------------------------------------------------- /efs.tf: -------------------------------------------------------------------------------- 1 | resource "aws_efs_file_system" "k8s_persistent_storage" { 2 | count = var.efs_persistent_storage ? 1 : 0 3 | creation_token = "${var.common_prefix}-efs-persistent-storage-${var.environment}" 4 | encrypted = true 5 | 6 | tags = merge( 7 | local.global_tags, 8 | { 9 | "Name" = lower("${var.common_prefix}-efs-persistent-storage-${var.environment}") 10 | } 11 | ) 12 | } 13 | 14 | resource "aws_efs_mount_target" "k8s_persistent_storage_mount_target" { 15 | count = var.efs_persistent_storage ? length(var.vpc_private_subnets) : 0 16 | file_system_id = aws_efs_file_system.k8s_persistent_storage[0].id 17 | subnet_id = var.vpc_private_subnets[count.index] 18 | security_groups = [aws_security_group.efs_sg[0].id] 19 | } -------------------------------------------------------------------------------- /local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | k8s_tls_san_public = var.create_extlb && var.expose_kubeapi ? aws_lb.external_lb[0].dns_name : "" 3 | kubeconfig_secret_name = "${var.common_prefix}-kubeconfig/${var.cluster_name}/${var.environment}/v1" 4 | kubeadm_ca_secret_name = "${var.common_prefix}-kubeadm-ca/${var.cluster_name}/${var.environment}/v1" 5 | kubeadm_token_secret_name = "${var.common_prefix}-kubeadm-token/${var.cluster_name}/${var.environment}/v1" 6 | kubeadm_cert_secret_name = "${var.common_prefix}-kubeadm-secret/${var.cluster_name}/${var.environment}/v1" 7 | global_tags = { 8 | environment = "${var.environment}" 9 | provisioner = "terraform" 10 | terraform_module = "https://github.com/garutilorenzo/k8s-aws-terraform-cluster" 11 | k8s_cluster_name = "${var.cluster_name}" 12 | application = "k8s" 13 | } 14 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as 12 | # password, private keys, and other secrets. These should not be part of version 13 | # control as they are data points which are potentially sensitive and subject 14 | # to change depending on the environment. 15 | # 16 | *.tfvars 17 | 18 | # Ignore override files as they are usually used to override resources locally and so 19 | # are not checked in 20 | override.tf 21 | override.tf.json 22 | *_override.tf 23 | *_override.tf.json 24 | 25 | # Include override files you do wish to add to version control using negated pattern 26 | # 27 | # !example_override.tf 28 | 29 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 30 | # example: *tfplan* 31 | 32 | # Ignore CLI configuration files 33 | .terraformrc 34 | terraform.rc 35 | 36 | *.json 37 | 38 | *Pipfile 39 | *Pipfile.lock 40 | 41 | main.tf_ori -------------------------------------------------------------------------------- /k8slb.tf: -------------------------------------------------------------------------------- 1 | resource "aws_lb" "k8s_server_lb" { 2 | name = "${var.common_prefix}-int-lb-${var.environment}" 3 | load_balancer_type = "network" 4 | internal = "true" 5 | subnets = var.vpc_private_subnets 6 | 7 | enable_cross_zone_load_balancing = true 8 | 9 | tags = merge( 10 | local.global_tags, 11 | { 12 | "Name" = lower("${var.common_prefix}-int-lb-${var.environment}") 13 | } 14 | ) 15 | } 16 | 17 | resource "aws_lb_listener" "k8s_server_listener" { 18 | load_balancer_arn = aws_lb.k8s_server_lb.arn 19 | 20 | protocol = "TCP" 21 | port = var.kube_api_port 22 | 23 | default_action { 24 | type = "forward" 25 | target_group_arn = aws_lb_target_group.k8s_server_tg.arn 26 | } 27 | 28 | tags = merge( 29 | local.global_tags, 30 | { 31 | "Name" = lower("${var.common_prefix}-kubeapi-listener-${var.environment}") 32 | } 33 | ) 34 | } 35 | 36 | resource "aws_lb_target_group" "k8s_server_tg" { 37 | port = var.kube_api_port 38 | protocol = "TCP" 39 | vpc_id = var.vpc_id 40 | preserve_client_ip = false 41 | 42 | depends_on = [ 43 | aws_lb.k8s_server_lb 44 | ] 45 | 46 | health_check { 47 | protocol = "TCP" 48 | interval = 10 49 | } 50 | 51 | lifecycle { 52 | create_before_destroy = true 53 | } 54 | 55 | tags = merge( 56 | local.global_tags, 57 | { 58 | "Name" = lower("${var.common_prefix}-internal-lb-tg-kubeapi-${var.environment}") 59 | } 60 | ) 61 | } 62 | 63 | resource "aws_autoscaling_attachment" "k8s_server_target_kubeapi" { 64 | 65 | depends_on = [ 66 | aws_autoscaling_group.k8s_servers_asg, 67 | aws_lb_target_group.k8s_server_tg 68 | ] 69 | 70 | autoscaling_group_name = aws_autoscaling_group.k8s_servers_asg.name 71 | lb_target_group_arn = aws_lb_target_group.k8s_server_tg.arn 72 | } -------------------------------------------------------------------------------- /template.tf: -------------------------------------------------------------------------------- 1 | resource "aws_launch_template" "k8s_server" { 2 | name_prefix = "${var.common_prefix}-server-tpl-${var.environment}" 3 | image_id = var.ami 4 | instance_type = var.default_instance_type 5 | user_data = data.template_cloudinit_config.k8s_server.rendered 6 | 7 | lifecycle { 8 | create_before_destroy = true 9 | } 10 | 11 | iam_instance_profile { 12 | name = aws_iam_instance_profile.k8s_instance_profile.name 13 | } 14 | 15 | block_device_mappings { 16 | device_name = "/dev/sda1" 17 | 18 | ebs { 19 | volume_size = 20 20 | encrypted = true 21 | } 22 | } 23 | 24 | key_name = var.ssk_key_pair_name 25 | 26 | network_interfaces { 27 | associate_public_ip_address = var.ec2_associate_public_ip_address 28 | security_groups = [aws_security_group.k8s_sg.id] 29 | } 30 | 31 | tags = merge( 32 | local.global_tags, 33 | { 34 | "Name" = lower("${var.common_prefix}-server-tpl-${var.environment}") 35 | } 36 | ) 37 | } 38 | 39 | resource "aws_launch_template" "k8s_worker" { 40 | name_prefix = "${var.common_prefix}-worker-tpl-${var.environment}" 41 | image_id = var.ami 42 | instance_type = var.default_instance_type 43 | user_data = data.template_cloudinit_config.k8s_worker.rendered 44 | 45 | lifecycle { 46 | create_before_destroy = true 47 | } 48 | 49 | iam_instance_profile { 50 | name = aws_iam_instance_profile.k8s_instance_profile.name 51 | } 52 | 53 | block_device_mappings { 54 | device_name = "/dev/sda1" 55 | 56 | ebs { 57 | volume_size = 20 58 | encrypted = true 59 | } 60 | } 61 | 62 | key_name = var.ssk_key_pair_name 63 | 64 | network_interfaces { 65 | associate_public_ip_address = var.ec2_associate_public_ip_address 66 | security_groups = [aws_security_group.k8s_sg.id] 67 | } 68 | 69 | tags = merge( 70 | local.global_tags, 71 | { 72 | "Name" = lower("${var.common_prefix}-worker-tpl-${var.environment}") 73 | } 74 | ) 75 | } -------------------------------------------------------------------------------- /examples/main.tf: -------------------------------------------------------------------------------- 1 | variable "AWS_ACCESS_KEY" { 2 | 3 | } 4 | 5 | variable "AWS_SECRET_KEY" { 6 | 7 | } 8 | 9 | variable "environment" { 10 | default = "staging" 11 | } 12 | 13 | variable "AWS_REGION" { 14 | default = "" 15 | } 16 | 17 | variable "my_public_ip_cidr" { 18 | default = "" 19 | } 20 | 21 | variable "vpc_cidr_block" { 22 | default = "" 23 | } 24 | 25 | variable "certmanager_email_address" { 26 | default = "" 27 | } 28 | 29 | variable "ssk_key_pair_name" { 30 | default = "" 31 | } 32 | 33 | module "private-vpc" { 34 | region = var.AWS_REGION 35 | my_public_ip_cidr = var.my_public_ip_cidr 36 | vpc_cidr_block = var.vpc_cidr_block 37 | environment = var.environment 38 | source = "github.com/garutilorenzo/aws-terraform-examples/private-vpc" 39 | } 40 | 41 | output "private_subnets_ids" { 42 | value = module.private-vpc.private_subnet_ids 43 | } 44 | 45 | output "public_subnets_ids" { 46 | value = module.private-vpc.public_subnet_ids 47 | } 48 | 49 | output "vpc_id" { 50 | value = module.private-vpc.vpc_id 51 | } 52 | 53 | module "k8s-cluster" { 54 | ssk_key_pair_name = var.ssk_key_pair_name 55 | environment = var.environment 56 | vpc_id = module.private-vpc.vpc_id 57 | vpc_private_subnets = module.private-vpc.private_subnet_ids 58 | vpc_public_subnets = module.private-vpc.public_subnet_ids 59 | vpc_subnet_cidr = var.vpc_cidr_block 60 | my_public_ip_cidr = var.my_public_ip_cidr 61 | create_extlb = true 62 | install_nginx_ingress = true 63 | efs_persistent_storage = true 64 | expose_kubeapi = true 65 | install_certmanager = true 66 | certmanager_email_address = var.certmanager_email_address 67 | source = "github.com/garutilorenzo/k8s-aws-terraform-cluster" 68 | } 69 | 70 | output "k8s_dns_name" { 71 | value = module.k8s-cluster.k8s_dns_name 72 | } 73 | 74 | output "k8s_server_private_ips" { 75 | value = module.k8s-cluster.k8s_server_private_ips 76 | } 77 | 78 | output "k8s_workers_private_ips" { 79 | value = module.k8s-cluster.k8s_workers_private_ips 80 | } -------------------------------------------------------------------------------- /files/install_k8s_worker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wait_lb() { 4 | while [ true ] 5 | do 6 | curl --output /dev/null --silent -k https://${control_plane_url}:${kube_api_port} 7 | if [[ "$?" -eq 0 ]]; then 8 | break 9 | fi 10 | sleep 5 11 | echo "wait for LB" 12 | done 13 | } 14 | 15 | wait_for_ca_secret(){ 16 | res=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 17 | while [[ -z "$res" || "$res" == "${default_secret_placeholder}" ]] 18 | do 19 | echo "Waiting the ca hash ..." 20 | res=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 21 | sleep 1 22 | done 23 | 24 | res_token=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 25 | while [[ -z "$res_token" || "$res_token" == "${default_secret_placeholder}" ]] 26 | do 27 | echo "Waiting the ca hash ..." 28 | res_token=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 29 | sleep 1 30 | done 31 | } 32 | 33 | render_kubejoin(){ 34 | 35 | HOSTNAME=$(hostname) 36 | ADVERTISE_ADDR=$(ip -o route get to 8.8.8.8 | grep -Po '(?<=src )(\S+)') 37 | CA_HASH=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 38 | KUBEADM_TOKEN=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 39 | 40 | cat <<-EOF > /root/kubeadm-join-worker.yaml 41 | --- 42 | apiVersion: kubeadm.k8s.io/v1beta3 43 | kind: JoinConfiguration 44 | discovery: 45 | bootstrapToken: 46 | token: $KUBEADM_TOKEN 47 | apiServerEndpoint: ${control_plane_url}:${kube_api_port} 48 | caCertHashes: 49 | - sha256:$CA_HASH 50 | localAPIEndpoint: 51 | advertiseAddress: $ADVERTISE_ADDR 52 | bindPort: ${kube_api_port} 53 | nodeRegistration: 54 | criSocket: /run/containerd/containerd.sock 55 | imagePullPolicy: IfNotPresent 56 | name: $HOSTNAME 57 | taints: null 58 | --- 59 | kind: KubeletConfiguration 60 | apiVersion: kubelet.config.k8s.io/v1beta1 61 | cgroupDriver: systemd 62 | EOF 63 | } 64 | 65 | k8s_join(){ 66 | kubeadm join --config /root/kubeadm-join-worker.yaml 67 | } 68 | 69 | wait_lb 70 | 71 | wait_for_ca_secret 72 | render_kubejoin 73 | k8s_join 74 | -------------------------------------------------------------------------------- /examples/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.9.0" 6 | hashes = [ 7 | "h1:mvg6WWqqUvgUq6wYCWg/zqpND/5yIz3plIL1IOR50Rs=", 8 | "zh:032424d4686ce2ff7c5a4a738491635616afbf6e06b3e7e6a754baa031d1265d", 9 | "zh:1e530b4020544ec94e1fe7b1e4296640eb12cf1bf4f79cd6429ff2c4e6fffaf3", 10 | "zh:24d2eee57a4c78039959dd9bb6dff2b75ed0483d44929550c067c3488307dc62", 11 | "zh:3ad6d736722059664e790a358eacf0e0e60973ec44e70142fb503275de2116c1", 12 | "zh:3f34d81acf86c61ddd271e9c4b8215765037463c3fe3c7aea1dc32a509020cfb", 13 | "zh:65a04aa615fc320059a0871702c83b6be10bce2064056096b46faffe768a698e", 14 | "zh:7fb56c3ce1fe77983627e2931e7c7b73152180c4dfb03e793413d0137c85d6b2", 15 | "zh:90c94cb9d7352468bcd5ba21a56099fe087a072b1936d86f47d54c2a012b708a", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:a109c5f01ed48852fe17847fa8a116dfdb81500794a9cf7e5ef92ea6dec20431", 18 | "zh:a27c5396077a36ac2801d4c1c1132201a9225a65bba0e3b3aded9cc18f2c38ff", 19 | "zh:a86ad796ccb0f2cb8f0ca069c774dbf74964edd3282529726816c72e22164b3c", 20 | "zh:bda8afc64091a2a72e0cc38fde937b2163b1b072a5c41310d255901207571afd", 21 | "zh:d22473894cd7e94b7a971793dd07309569f82913a10e4bd6c22e04f362f03bb9", 22 | "zh:f4dbb6d13511290a5274f5b202e6d9997643f86e4c48e8c5e3c204121082851a", 23 | ] 24 | } 25 | 26 | provider "registry.terraform.io/hashicorp/template" { 27 | version = "2.2.0" 28 | hashes = [ 29 | "h1:94qn780bi1qjrbC3uQtjJh3Wkfwd5+tTtJHOb7KTg9w=", 30 | "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", 31 | "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", 32 | "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", 33 | "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", 34 | "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", 35 | "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", 36 | "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", 37 | "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", 38 | "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", 39 | "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /deployments/eck-filebeat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: beat.k8s.elastic.co/v1beta1 3 | kind: Beat 4 | metadata: 5 | name: k8s-eck-filebeat 6 | spec: 7 | type: filebeat 8 | version: 8.8.2 9 | elasticsearchRef: 10 | name: k8s-eck 11 | kibanaRef: 12 | name: k8s-eck-kibana 13 | config: 14 | filebeat.autodiscover.providers: 15 | - node: ${NODE_NAME} 16 | type: kubernetes 17 | hints.default_config.enabled: "false" 18 | templates: 19 | - condition.equals.kubernetes.namespace: default 20 | config: 21 | - paths: ["/var/log/containers/*${data.kubernetes.container.id}.log"] 22 | type: container 23 | processors: 24 | - add_cloud_metadata: {} 25 | - add_host_metadata: {} 26 | daemonSet: 27 | podTemplate: 28 | spec: 29 | serviceAccountName: filebeat 30 | automountServiceAccountToken: true 31 | terminationGracePeriodSeconds: 30 32 | dnsPolicy: ClusterFirstWithHostNet 33 | hostNetwork: true # Allows to provide richer host metadata 34 | containers: 35 | - name: filebeat 36 | securityContext: 37 | runAsUser: 0 38 | # If using Red Hat OpenShift uncomment this: 39 | #privileged: true 40 | volumeMounts: 41 | - name: varlogcontainers 42 | mountPath: /var/log/containers 43 | - name: varlogpods 44 | mountPath: /var/log/pods 45 | - name: varlibdockercontainers 46 | mountPath: /var/lib/docker/containers 47 | env: 48 | - name: NODE_NAME 49 | valueFrom: 50 | fieldRef: 51 | fieldPath: spec.nodeName 52 | volumes: 53 | - name: varlogcontainers 54 | hostPath: 55 | path: /var/log/containers 56 | - name: varlogpods 57 | hostPath: 58 | path: /var/log/pods 59 | - name: varlibdockercontainers 60 | hostPath: 61 | path: /var/lib/docker/containers 62 | --- 63 | apiVersion: rbac.authorization.k8s.io/v1 64 | kind: ClusterRole 65 | metadata: 66 | name: filebeat 67 | rules: 68 | - apiGroups: [""] # "" indicates the core API group 69 | resources: 70 | - namespaces 71 | - pods 72 | - nodes 73 | verbs: 74 | - get 75 | - watch 76 | - list 77 | --- 78 | apiVersion: v1 79 | kind: ServiceAccount 80 | metadata: 81 | name: filebeat 82 | --- 83 | apiVersion: rbac.authorization.k8s.io/v1 84 | kind: ClusterRoleBinding 85 | metadata: 86 | name: filebeat 87 | namespace: default 88 | subjects: 89 | - kind: ServiceAccount 90 | name: filebeat 91 | namespace: default 92 | roleRef: 93 | kind: ClusterRole 94 | name: filebeat 95 | apiGroup: rbac.authorization.k8s.io -------------------------------------------------------------------------------- /secrets.tf: -------------------------------------------------------------------------------- 1 | resource "aws_secretsmanager_secret" "kubeconfig_secret" { 2 | name = local.kubeconfig_secret_name 3 | description = "Kubeconfig k8s. Cluster name: ${var.cluster_name}, environment: ${var.environment}" 4 | 5 | tags = merge( 6 | local.global_tags, 7 | { 8 | "Name" = lower("${local.kubeconfig_secret_name}") 9 | } 10 | ) 11 | } 12 | 13 | resource "aws_secretsmanager_secret" "kubeadm_ca" { 14 | name = local.kubeadm_ca_secret_name 15 | description = "Kubeadm CA. Cluster name: ${var.cluster_name}, environment: ${var.environment}" 16 | 17 | tags = merge( 18 | local.global_tags, 19 | { 20 | "Name" = lower("${local.kubeadm_ca_secret_name}") 21 | } 22 | ) 23 | } 24 | 25 | resource "aws_secretsmanager_secret" "kubeadm_token" { 26 | name = local.kubeadm_token_secret_name 27 | description = "Kubeadm token. Cluster name: ${var.cluster_name}, environment: ${var.environment}" 28 | 29 | tags = merge( 30 | local.global_tags, 31 | { 32 | "Name" = lower("${local.kubeadm_token_secret_name}") 33 | } 34 | ) 35 | } 36 | 37 | resource "aws_secretsmanager_secret" "kubeadm_cert" { 38 | name = local.kubeadm_cert_secret_name 39 | description = "Kubeadm cert. Cluster name: ${var.cluster_name}, environment: ${var.environment}" 40 | 41 | tags = merge( 42 | local.global_tags, 43 | { 44 | "Name" = lower("${local.kubeadm_cert_secret_name}") 45 | } 46 | ) 47 | } 48 | 49 | # secret default values 50 | 51 | resource "aws_secretsmanager_secret_version" "kubeconfig_secret_default" { 52 | secret_id = aws_secretsmanager_secret.kubeconfig_secret.id 53 | secret_string = var.default_secret_placeholder 54 | } 55 | 56 | resource "aws_secretsmanager_secret_version" "kubeadm_ca_default" { 57 | secret_id = aws_secretsmanager_secret.kubeadm_ca.id 58 | secret_string = var.default_secret_placeholder 59 | } 60 | 61 | resource "aws_secretsmanager_secret_version" "kubeadm_token_default" { 62 | secret_id = aws_secretsmanager_secret.kubeadm_token.id 63 | secret_string = var.default_secret_placeholder 64 | } 65 | 66 | resource "aws_secretsmanager_secret_version" "kubeadm_cert_default" { 67 | secret_id = aws_secretsmanager_secret.kubeadm_cert.id 68 | secret_string = var.default_secret_placeholder 69 | } 70 | 71 | # Secret Policies 72 | 73 | resource "aws_secretsmanager_secret_policy" "kubeconfig_secret_policy" { 74 | secret_arn = aws_secretsmanager_secret.kubeconfig_secret.arn 75 | 76 | policy = jsonencode({ 77 | Version = "2012-10-17", 78 | Statement = [ 79 | { 80 | Effect = "Allow", 81 | Principal = { 82 | AWS = "${aws_iam_role.k8s_iam_role.arn}" 83 | }, 84 | Action = [ 85 | "secretsmanager:GetSecretValue", 86 | "secretsmanager:UpdateSecret", 87 | "secretsmanager:DeleteSecret", 88 | "secretsmanager:DescribeSecret", 89 | "secretsmanager:ListSecrets", 90 | "secretsmanager:CreateSecret", 91 | "secretsmanager:PutSecretValue" 92 | ] 93 | Resource = [ 94 | "${aws_secretsmanager_secret.kubeconfig_secret.arn}" 95 | ] 96 | } 97 | ] 98 | }) 99 | } -------------------------------------------------------------------------------- /security.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "k8s_sg" { 2 | vpc_id = var.vpc_id 3 | name = "k8s_sg" 4 | description = "Kubernetes ingress rules" 5 | 6 | lifecycle { 7 | create_before_destroy = true 8 | } 9 | 10 | tags = merge( 11 | local.global_tags, 12 | { 13 | "Name" = lower("${var.common_prefix}-allow-strict-${var.environment}") 14 | } 15 | ) 16 | } 17 | 18 | resource "aws_security_group_rule" "ingress_self" { 19 | type = "ingress" 20 | from_port = 0 21 | to_port = 0 22 | protocol = "-1" 23 | self = true 24 | security_group_id = aws_security_group.k8s_sg.id 25 | } 26 | 27 | resource "aws_security_group_rule" "ingress_kubeapi" { 28 | type = "ingress" 29 | from_port = var.kube_api_port 30 | to_port = var.kube_api_port 31 | protocol = "tcp" 32 | cidr_blocks = [var.vpc_subnet_cidr] 33 | security_group_id = aws_security_group.k8s_sg.id 34 | } 35 | 36 | resource "aws_security_group_rule" "ingress_ssh" { 37 | type = "ingress" 38 | from_port = 22 39 | to_port = 22 40 | protocol = "tcp" 41 | cidr_blocks = [var.my_public_ip_cidr] 42 | security_group_id = aws_security_group.k8s_sg.id 43 | } 44 | 45 | resource "aws_security_group_rule" "egress_all" { 46 | type = "egress" 47 | from_port = 0 48 | to_port = 0 49 | protocol = "-1" 50 | cidr_blocks = ["0.0.0.0/0"] 51 | security_group_id = aws_security_group.k8s_sg.id 52 | } 53 | 54 | resource "aws_security_group_rule" "allow_lb_http_traffic" { 55 | count = var.create_extlb ? 1 : 0 56 | type = "ingress" 57 | from_port = var.extlb_listener_http_port 58 | to_port = var.extlb_listener_http_port 59 | protocol = "tcp" 60 | cidr_blocks = ["0.0.0.0/0"] 61 | security_group_id = aws_security_group.k8s_sg.id 62 | } 63 | 64 | resource "aws_security_group_rule" "allow_lb_https_traffic" { 65 | count = var.create_extlb ? 1 : 0 66 | type = "ingress" 67 | from_port = var.extlb_listener_https_port 68 | to_port = var.extlb_listener_https_port 69 | protocol = "tcp" 70 | cidr_blocks = ["0.0.0.0/0"] 71 | security_group_id = aws_security_group.k8s_sg.id 72 | } 73 | 74 | resource "aws_security_group_rule" "allow_lb_kubeapi_traffic" { 75 | count = var.create_extlb && var.expose_kubeapi ? 1 : 0 76 | type = "ingress" 77 | from_port = var.kube_api_port 78 | to_port = var.kube_api_port 79 | protocol = "tcp" 80 | cidr_blocks = [var.my_public_ip_cidr] 81 | security_group_id = aws_security_group.k8s_sg.id 82 | } 83 | 84 | resource "aws_security_group" "efs_sg" { 85 | count = var.efs_persistent_storage ? 1 : 0 86 | vpc_id = var.vpc_id 87 | name = "${var.common_prefix}-efs-sg-${var.environment}" 88 | description = "Allow EFS access from VPC subnets" 89 | 90 | egress { 91 | from_port = 0 92 | to_port = 0 93 | protocol = "-1" 94 | cidr_blocks = ["0.0.0.0/0"] 95 | } 96 | 97 | ingress { 98 | from_port = 2049 99 | to_port = 2049 100 | protocol = "tcp" 101 | cidr_blocks = [var.vpc_subnet_cidr] 102 | } 103 | 104 | tags = merge( 105 | local.global_tags, 106 | { 107 | "Name" = lower("${var.common_prefix}-efs-sg-${var.environment}") 108 | } 109 | ) 110 | } -------------------------------------------------------------------------------- /deployments/eck-metricbeat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: beat.k8s.elastic.co/v1beta1 3 | kind: Beat 4 | metadata: 5 | name: k8s-eck-metricbeat 6 | spec: 7 | type: metricbeat 8 | version: 8.8.2 9 | elasticsearchRef: 10 | name: k8s-eck 11 | kibanaRef: 12 | name: k8s-eck-kibana 13 | config: 14 | metricbeat: 15 | autodiscover: 16 | providers: 17 | - hints: 18 | default_config: {} 19 | enabled: "true" 20 | node: ${NODE_NAME} 21 | type: kubernetes 22 | modules: 23 | - module: system 24 | period: 10s 25 | metricsets: 26 | - cpu 27 | - load 28 | - memory 29 | - network 30 | - process 31 | - process_summary 32 | process: 33 | include_top_n: 34 | by_cpu: 5 35 | by_memory: 5 36 | processes: 37 | - .* 38 | - module: system 39 | period: 1m 40 | metricsets: 41 | - filesystem 42 | - fsstat 43 | processors: 44 | - drop_event: 45 | when: 46 | regexp: 47 | system: 48 | filesystem: 49 | mount_point: ^/(sys|cgroup|proc|dev|etc|host|lib)($|/) 50 | - module: kubernetes 51 | period: 10s 52 | node: ${NODE_NAME} 53 | hosts: 54 | - https://${NODE_NAME}:10250 55 | bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token 56 | ssl: 57 | verification_mode: none 58 | metricsets: 59 | - node 60 | - system 61 | - pod 62 | - container 63 | - volume 64 | processors: 65 | - add_cloud_metadata: {} 66 | - add_host_metadata: {} 67 | daemonSet: 68 | podTemplate: 69 | spec: 70 | serviceAccountName: metricbeat 71 | automountServiceAccountToken: true # some older Beat versions are depending on this settings presence in k8s context 72 | containers: 73 | - args: 74 | - -e 75 | - -c 76 | - /etc/beat.yml 77 | - -system.hostfs=/hostfs 78 | name: metricbeat 79 | volumeMounts: 80 | - mountPath: /hostfs/sys/fs/cgroup 81 | name: cgroup 82 | - mountPath: /var/run/docker.sock 83 | name: dockersock 84 | - mountPath: /hostfs/proc 85 | name: proc 86 | env: 87 | - name: NODE_NAME 88 | valueFrom: 89 | fieldRef: 90 | fieldPath: spec.nodeName 91 | dnsPolicy: ClusterFirstWithHostNet 92 | hostNetwork: true # Allows to provide richer host metadata 93 | securityContext: 94 | runAsUser: 0 95 | terminationGracePeriodSeconds: 30 96 | volumes: 97 | - hostPath: 98 | path: /sys/fs/cgroup 99 | name: cgroup 100 | - hostPath: 101 | path: /var/run/docker.sock 102 | name: dockersock 103 | - hostPath: 104 | path: /proc 105 | name: proc 106 | --- 107 | # permissions needed for metricbeat 108 | # source: https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-module-kubernetes.html 109 | apiVersion: rbac.authorization.k8s.io/v1 110 | kind: ClusterRole 111 | metadata: 112 | name: metricbeat 113 | namespace: default 114 | rules: 115 | - apiGroups: 116 | - "" 117 | resources: 118 | - nodes 119 | - namespaces 120 | - events 121 | - pods 122 | verbs: 123 | - get 124 | - list 125 | - watch 126 | - apiGroups: 127 | - "extensions" 128 | resources: 129 | - replicasets 130 | verbs: 131 | - get 132 | - list 133 | - watch 134 | - apiGroups: 135 | - apps 136 | resources: 137 | - statefulsets 138 | - deployments 139 | - replicasets 140 | verbs: 141 | - get 142 | - list 143 | - watch 144 | - apiGroups: 145 | - "" 146 | resources: 147 | - nodes/stats 148 | verbs: 149 | - get 150 | - nonResourceURLs: 151 | - /metrics 152 | verbs: 153 | - get 154 | --- 155 | apiVersion: v1 156 | kind: ServiceAccount 157 | metadata: 158 | name: metricbeat 159 | namespace: default 160 | --- 161 | apiVersion: rbac.authorization.k8s.io/v1 162 | kind: ClusterRoleBinding 163 | metadata: 164 | name: metricbeat 165 | namespace: default 166 | subjects: 167 | - kind: ServiceAccount 168 | name: metricbeat 169 | namespace: default 170 | roleRef: 171 | kind: ClusterRole 172 | name: metricbeat 173 | apiGroup: rbac.authorization.k8s.io -------------------------------------------------------------------------------- /asg.tf: -------------------------------------------------------------------------------- 1 | resource "aws_autoscaling_group" "k8s_servers_asg" { 2 | name = "${var.common_prefix}-servers-asg-${var.environment}" 3 | wait_for_capacity_timeout = "5m" 4 | vpc_zone_identifier = var.vpc_private_subnets 5 | 6 | lifecycle { 7 | create_before_destroy = true 8 | ignore_changes = [load_balancers, target_group_arns] 9 | } 10 | 11 | mixed_instances_policy { 12 | instances_distribution { 13 | on_demand_base_capacity = 0 14 | on_demand_percentage_above_base_capacity = 20 15 | spot_allocation_strategy = "capacity-optimized" 16 | } 17 | 18 | launch_template { 19 | launch_template_specification { 20 | launch_template_id = aws_launch_template.k8s_server.id 21 | version = "$Latest" 22 | } 23 | 24 | dynamic "override" { 25 | for_each = var.instance_types 26 | content { 27 | instance_type = override.value 28 | weighted_capacity = "1" 29 | } 30 | } 31 | } 32 | } 33 | 34 | desired_capacity = var.k8s_server_desired_capacity 35 | min_size = var.k8s_server_min_capacity 36 | max_size = var.k8s_server_max_capacity 37 | health_check_grace_period = 300 38 | health_check_type = "EC2" 39 | force_delete = true 40 | 41 | dynamic "tag" { 42 | for_each = local.global_tags 43 | content { 44 | key = tag.key 45 | value = tag.value 46 | propagate_at_launch = true 47 | } 48 | } 49 | 50 | tag { 51 | key = "Name" 52 | value = "${var.common_prefix}-server-${var.environment}" 53 | propagate_at_launch = true 54 | } 55 | 56 | tag { 57 | key = "k8s-instance-type" 58 | value = "k8s-server" 59 | propagate_at_launch = true 60 | } 61 | 62 | tag { 63 | key = "k8s.io/cluster-autoscaler/enabled" 64 | value = "" 65 | propagate_at_launch = true 66 | } 67 | 68 | tag { 69 | key = "k8s.io/cluster-autoscaler/${var.cluster_name}" 70 | value = "" 71 | propagate_at_launch = true 72 | } 73 | } 74 | 75 | resource "aws_autoscaling_group" "k8s_workers_asg" { 76 | name = "${var.common_prefix}-workers-asg-${var.environment}" 77 | vpc_zone_identifier = var.vpc_private_subnets 78 | 79 | lifecycle { 80 | create_before_destroy = true 81 | ignore_changes = [load_balancers, target_group_arns] 82 | } 83 | 84 | mixed_instances_policy { 85 | instances_distribution { 86 | on_demand_base_capacity = 0 87 | on_demand_percentage_above_base_capacity = 20 88 | spot_allocation_strategy = "capacity-optimized" 89 | } 90 | 91 | launch_template { 92 | launch_template_specification { 93 | launch_template_id = aws_launch_template.k8s_worker.id 94 | version = "$Latest" 95 | } 96 | 97 | dynamic "override" { 98 | for_each = var.instance_types 99 | content { 100 | instance_type = override.value 101 | weighted_capacity = "1" 102 | } 103 | } 104 | } 105 | } 106 | 107 | desired_capacity = var.k8s_worker_desired_capacity 108 | min_size = var.k8s_worker_min_capacity 109 | max_size = var.k8s_worker_max_capacity 110 | health_check_grace_period = 300 111 | health_check_type = "EC2" 112 | force_delete = true 113 | 114 | dynamic "tag" { 115 | for_each = local.global_tags 116 | content { 117 | key = tag.key 118 | value = tag.value 119 | propagate_at_launch = true 120 | } 121 | } 122 | 123 | tag { 124 | key = "Name" 125 | value = "${var.common_prefix}-worker-${var.environment}" 126 | propagate_at_launch = true 127 | } 128 | 129 | tag { 130 | key = "k8s-instance-type" 131 | value = "k8s-worker" 132 | propagate_at_launch = true 133 | } 134 | 135 | tag { 136 | key = "k8s.io/cluster-autoscaler/enabled" 137 | value = "" 138 | propagate_at_launch = true 139 | } 140 | 141 | tag { 142 | key = "k8s.io/cluster-autoscaler/${var.cluster_name}" 143 | value = "" 144 | propagate_at_launch = true 145 | } 146 | } -------------------------------------------------------------------------------- /data.tf: -------------------------------------------------------------------------------- 1 | data "aws_iam_policy" "AmazonEC2ReadOnlyAccess" { 2 | arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess" 3 | } 4 | 5 | data "aws_iam_policy" "AmazonSSMManagedInstanceCore" { 6 | arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" 7 | } 8 | 9 | data "template_cloudinit_config" "k8s_server" { 10 | gzip = true 11 | base64_encode = true 12 | 13 | part { 14 | filename = "init.cfg" 15 | content_type = "text/cloud-config" 16 | content = templatefile("${path.module}/files/cloud-config-base.yaml", {}) 17 | } 18 | 19 | part { 20 | content_type = "text/x-shellscript" 21 | content = templatefile("${path.module}/files/install_k8s_utils.sh", { 22 | k8s_version = var.k8s_version 23 | }) 24 | } 25 | 26 | part { 27 | content_type = "text/x-shellscript" 28 | content = templatefile("${path.module}/files/install_k8s.sh", { 29 | is_k8s_server = true, 30 | k8s_version = var.k8s_version, 31 | k8s_dns_domain = var.k8s_dns_domain, 32 | k8s_pod_subnet = var.k8s_pod_subnet, 33 | k8s_service_subnet = var.k8s_service_subnet, 34 | kubeadm_ca_secret_name = local.kubeadm_ca_secret_name, 35 | kubeadm_token_secret_name = local.kubeadm_token_secret_name, 36 | kubeadm_cert_secret_name = local.kubeadm_cert_secret_name, 37 | kubeconfig_secret_name = local.kubeconfig_secret_name, 38 | kube_api_port = var.kube_api_port, 39 | control_plane_url = aws_lb.k8s_server_lb.dns_name, 40 | install_nginx_ingress = var.install_nginx_ingress, 41 | nginx_ingress_release = var.nginx_ingress_release, 42 | efs_persistent_storage = var.efs_persistent_storage, 43 | efs_csi_driver_release = var.efs_csi_driver_release, 44 | efs_filesystem_id = var.efs_persistent_storage ? aws_efs_file_system.k8s_persistent_storage[0].id : "", 45 | install_certmanager = var.install_certmanager, 46 | certmanager_release = var.certmanager_release, 47 | install_node_termination_handler = var.install_node_termination_handler, 48 | node_termination_handler_release = var.node_termination_handler_release, 49 | certmanager_email_address = var.certmanager_email_address, 50 | extlb_listener_http_port = var.extlb_listener_http_port, 51 | extlb_listener_https_port = var.extlb_listener_https_port, 52 | default_secret_placeholder = var.default_secret_placeholder, 53 | expose_kubeapi = var.expose_kubeapi, 54 | k8s_tls_san_public = local.k8s_tls_san_public 55 | }) 56 | } 57 | } 58 | 59 | data "template_cloudinit_config" "k8s_worker" { 60 | gzip = true 61 | base64_encode = true 62 | 63 | part { 64 | filename = "init.cfg" 65 | content_type = "text/cloud-config" 66 | content = templatefile("${path.module}/files/cloud-config-base.yaml", {}) 67 | } 68 | 69 | part { 70 | content_type = "text/x-shellscript" 71 | content = templatefile("${path.module}/files/install_k8s_utils.sh", { 72 | k8s_version = var.k8s_version 73 | }) 74 | } 75 | 76 | part { 77 | content_type = "text/x-shellscript" 78 | content = templatefile("${path.module}/files/install_k8s_worker.sh", { 79 | is_k8s_server = false, 80 | kubeadm_ca_secret_name = local.kubeadm_ca_secret_name, 81 | kubeadm_token_secret_name = local.kubeadm_token_secret_name, 82 | kubeadm_cert_secret_name = local.kubeadm_cert_secret_name, 83 | kube_api_port = var.kube_api_port, 84 | control_plane_url = aws_lb.k8s_server_lb.dns_name, 85 | default_secret_placeholder = var.default_secret_placeholder, 86 | }) 87 | } 88 | } 89 | 90 | data "aws_instances" "k8s_servers" { 91 | 92 | depends_on = [ 93 | aws_autoscaling_group.k8s_servers_asg, 94 | ] 95 | 96 | instance_tags = { 97 | for tag, value in merge(local.global_tags, { k8s-instance-type = "k8s-server" }) : tag => value 98 | } 99 | 100 | instance_state_names = ["running"] 101 | } 102 | 103 | data "aws_instances" "k8s_workers" { 104 | 105 | depends_on = [ 106 | aws_autoscaling_group.k8s_workers_asg, 107 | ] 108 | 109 | instance_tags = { 110 | for tag, value in merge(local.global_tags, { k8s-instance-type = "k8s-worker" }) : tag => value 111 | } 112 | 113 | instance_state_names = ["running"] 114 | } -------------------------------------------------------------------------------- /vars.tf: -------------------------------------------------------------------------------- 1 | variable "environment" { 2 | type = string 3 | } 4 | 5 | variable "ssk_key_pair_name" { 6 | type = string 7 | } 8 | 9 | variable "vpc_id" { 10 | type = string 11 | description = "The vpc id" 12 | } 13 | 14 | variable "my_public_ip_cidr" { 15 | type = string 16 | description = "My public ip CIDR" 17 | } 18 | 19 | variable "vpc_private_subnets" { 20 | type = list(any) 21 | description = "The private vpc subnets ids" 22 | } 23 | 24 | variable "vpc_public_subnets" { 25 | type = list(any) 26 | description = "The public vpc subnets ids" 27 | } 28 | 29 | variable "vpc_subnet_cidr" { 30 | type = string 31 | description = "VPC subnet CIDR" 32 | } 33 | 34 | variable "common_prefix" { 35 | type = string 36 | description = "" 37 | default = "k8s" 38 | } 39 | 40 | variable "ec2_associate_public_ip_address" { 41 | type = bool 42 | default = false 43 | } 44 | 45 | ## eu-west-1 46 | # Ubuntu 22.04 47 | # ami-0cffefff2d52e0a23 48 | 49 | # Amazon Linux 2 AMI (HVM) - Kernel 5.10, SSD Volume Type 50 | # ami-006be9ab6a140de6e 51 | 52 | variable "ami" { 53 | type = string 54 | default = "ami-0cffefff2d52e0a23" 55 | } 56 | 57 | variable "default_instance_type" { 58 | type = string 59 | default = "t3.medium" 60 | description = "Instance type to be used" 61 | } 62 | 63 | variable "instance_types" { 64 | description = "List of instance types to use" 65 | type = map(string) 66 | default = { 67 | asg_instance_type_1 = "t3.medium" 68 | asg_instance_type_2 = "t3a.medium" 69 | asg_instance_type_3 = "c5a.large" 70 | asg_instance_type_4 = "c6a.large" 71 | } 72 | } 73 | 74 | variable "k8s_version" { 75 | type = string 76 | default = "1.27.3" 77 | } 78 | 79 | variable "k8s_pod_subnet" { 80 | type = string 81 | default = "10.244.0.0/16" 82 | } 83 | 84 | variable "k8s_service_subnet" { 85 | type = string 86 | default = "10.96.0.0/12" 87 | } 88 | 89 | variable "k8s_dns_domain" { 90 | type = string 91 | default = "cluster.local" 92 | } 93 | 94 | variable "kube_api_port" { 95 | type = number 96 | default = 6443 97 | description = "Kubeapi Port" 98 | } 99 | 100 | variable "k8s_server_desired_capacity" { 101 | type = number 102 | default = 3 103 | description = "k8s server ASG desired capacity" 104 | } 105 | 106 | variable "k8s_server_min_capacity" { 107 | type = number 108 | default = 3 109 | description = "k8s server ASG min capacity" 110 | } 111 | 112 | variable "k8s_server_max_capacity" { 113 | type = number 114 | default = 4 115 | description = "k8s server ASG max capacity" 116 | } 117 | 118 | variable "k8s_worker_desired_capacity" { 119 | type = number 120 | default = 3 121 | description = "k8s server ASG desired capacity" 122 | } 123 | 124 | variable "k8s_worker_min_capacity" { 125 | type = number 126 | default = 3 127 | description = "k8s server ASG min capacity" 128 | } 129 | 130 | variable "k8s_worker_max_capacity" { 131 | type = number 132 | default = 4 133 | description = "k8s server ASG max capacity" 134 | } 135 | 136 | variable "cluster_name" { 137 | type = string 138 | default = "k8s-cluster" 139 | description = "Cluster name" 140 | } 141 | 142 | variable "install_nginx_ingress" { 143 | type = bool 144 | default = false 145 | description = "Create external LB true/false" 146 | } 147 | 148 | variable "nginx_ingress_release" { 149 | type = string 150 | default = "v1.8.1" 151 | } 152 | 153 | variable "install_certmanager" { 154 | type = bool 155 | default = false 156 | } 157 | 158 | variable "certmanager_release" { 159 | type = string 160 | default = "v1.12.2" 161 | } 162 | 163 | variable "certmanager_email_address" { 164 | type = string 165 | default = "changeme@example.com" 166 | } 167 | 168 | variable "create_extlb" { 169 | type = bool 170 | default = false 171 | description = "Create external LB true/false" 172 | } 173 | 174 | variable "efs_persistent_storage" { 175 | type = bool 176 | default = false 177 | } 178 | 179 | variable "efs_csi_driver_release" { 180 | type = string 181 | default = "v1.5.8" 182 | } 183 | 184 | variable "extlb_listener_http_port" { 185 | type = number 186 | default = 30080 187 | } 188 | 189 | variable "extlb_listener_https_port" { 190 | type = number 191 | default = 30443 192 | } 193 | 194 | variable "extlb_http_port" { 195 | type = number 196 | default = 80 197 | } 198 | 199 | variable "extlb_https_port" { 200 | type = number 201 | default = 443 202 | } 203 | 204 | variable "default_secret_placeholder" { 205 | type = string 206 | default = "DEFAULTPLACEHOLDER" 207 | } 208 | 209 | variable "expose_kubeapi" { 210 | type = bool 211 | default = false 212 | } 213 | 214 | variable "install_node_termination_handler" { 215 | type = bool 216 | default = true 217 | } 218 | 219 | variable "node_termination_handler_release" { 220 | type = string 221 | default = "v1.20.0" 222 | } 223 | -------------------------------------------------------------------------------- /lb.tf: -------------------------------------------------------------------------------- 1 | resource "aws_lb" "external_lb" { 2 | count = var.create_extlb ? 1 : 0 3 | name = "${var.common_prefix}-ext-lb-${var.environment}" 4 | load_balancer_type = "network" 5 | internal = "false" 6 | subnets = var.vpc_public_subnets 7 | 8 | enable_cross_zone_load_balancing = true 9 | 10 | tags = merge( 11 | local.global_tags, 12 | { 13 | "Name" = lower("${var.common_prefix}-ext-lb-${var.environment}") 14 | } 15 | ) 16 | } 17 | 18 | # HTTP 19 | resource "aws_lb_listener" "external_lb_listener_http" { 20 | count = var.create_extlb ? 1 : 0 21 | load_balancer_arn = aws_lb.external_lb[count.index].arn 22 | 23 | protocol = "TCP" 24 | port = var.extlb_http_port 25 | 26 | default_action { 27 | type = "forward" 28 | target_group_arn = aws_lb_target_group.external_lb_tg_http[count.index].arn 29 | } 30 | 31 | tags = merge( 32 | local.global_tags, 33 | { 34 | "Name" = lower("${var.common_prefix}-http-listener-${var.environment}") 35 | } 36 | ) 37 | } 38 | 39 | resource "aws_lb_target_group" "external_lb_tg_http" { 40 | count = var.create_extlb ? 1 : 0 41 | port = var.extlb_listener_http_port 42 | protocol = "TCP" 43 | vpc_id = var.vpc_id 44 | proxy_protocol_v2 = true 45 | 46 | depends_on = [ 47 | aws_lb.external_lb 48 | ] 49 | 50 | health_check { 51 | protocol = "TCP" 52 | } 53 | 54 | lifecycle { 55 | create_before_destroy = true 56 | } 57 | 58 | tags = merge( 59 | local.global_tags, 60 | { 61 | "Name" = lower("${var.common_prefix}-ext-lb-tg-http-${var.environment}") 62 | } 63 | ) 64 | } 65 | 66 | resource "aws_autoscaling_attachment" "target_http" { 67 | count = var.create_extlb ? 1 : 0 68 | depends_on = [ 69 | aws_autoscaling_group.k8s_workers_asg, 70 | aws_lb_target_group.external_lb_tg_http 71 | ] 72 | 73 | autoscaling_group_name = aws_autoscaling_group.k8s_workers_asg.name 74 | lb_target_group_arn = aws_lb_target_group.external_lb_tg_http[count.index].arn 75 | } 76 | 77 | # HTTPS 78 | resource "aws_lb_listener" "external_lb_listener_https" { 79 | count = var.create_extlb ? 1 : 0 80 | load_balancer_arn = aws_lb.external_lb[count.index].arn 81 | 82 | protocol = "TCP" 83 | port = var.extlb_https_port 84 | 85 | default_action { 86 | type = "forward" 87 | target_group_arn = aws_lb_target_group.external_lb_tg_https[count.index].arn 88 | } 89 | 90 | tags = merge( 91 | local.global_tags, 92 | { 93 | "Name" = lower("${var.common_prefix}-https-listener-${var.environment}") 94 | } 95 | ) 96 | } 97 | 98 | resource "aws_lb_target_group" "external_lb_tg_https" { 99 | count = var.create_extlb ? 1 : 0 100 | port = var.extlb_listener_https_port 101 | protocol = "TCP" 102 | vpc_id = var.vpc_id 103 | proxy_protocol_v2 = true 104 | 105 | depends_on = [ 106 | aws_lb.external_lb 107 | ] 108 | 109 | health_check { 110 | protocol = "TCP" 111 | } 112 | 113 | lifecycle { 114 | create_before_destroy = true 115 | } 116 | 117 | tags = merge( 118 | local.global_tags, 119 | { 120 | "Name" = lower("${var.common_prefix}-ext-lb-tg-https-${var.environment}") 121 | } 122 | ) 123 | } 124 | 125 | resource "aws_autoscaling_attachment" "target_https" { 126 | count = var.create_extlb ? 1 : 0 127 | depends_on = [ 128 | aws_autoscaling_group.k8s_workers_asg, 129 | aws_lb_target_group.external_lb_tg_https 130 | ] 131 | 132 | autoscaling_group_name = aws_autoscaling_group.k8s_workers_asg.name 133 | lb_target_group_arn = aws_lb_target_group.external_lb_tg_https[count.index].arn 134 | } 135 | 136 | # kubeapi 137 | 138 | resource "aws_lb_listener" "external_lb_listener_kubeapi" { 139 | count = var.expose_kubeapi ? 1 : 0 140 | load_balancer_arn = aws_lb.external_lb[count.index].arn 141 | 142 | protocol = "TCP" 143 | port = var.kube_api_port 144 | 145 | default_action { 146 | type = "forward" 147 | target_group_arn = aws_lb_target_group.external_lb_tg_kubeapi[count.index].arn 148 | } 149 | 150 | tags = merge( 151 | local.global_tags, 152 | { 153 | "Name" = lower("${var.common_prefix}-kubeapi-listener-${var.environment}") 154 | } 155 | ) 156 | } 157 | 158 | resource "aws_lb_target_group" "external_lb_tg_kubeapi" { 159 | count = var.expose_kubeapi ? 1 : 0 160 | port = var.kube_api_port 161 | protocol = "TCP" 162 | vpc_id = var.vpc_id 163 | 164 | depends_on = [ 165 | aws_lb.external_lb 166 | ] 167 | 168 | health_check { 169 | protocol = "TCP" 170 | } 171 | 172 | lifecycle { 173 | create_before_destroy = true 174 | } 175 | 176 | tags = merge( 177 | local.global_tags, 178 | { 179 | "Name" = lower("${var.common_prefix}-ext-lb-tg-kubeapi-${var.environment}") 180 | } 181 | ) 182 | } 183 | 184 | resource "aws_autoscaling_attachment" "target_kubeapi" { 185 | count = var.expose_kubeapi ? 1 : 0 186 | depends_on = [ 187 | aws_autoscaling_group.k8s_servers_asg, 188 | aws_lb_target_group.external_lb_tg_kubeapi 189 | ] 190 | 191 | autoscaling_group_name = aws_autoscaling_group.k8s_servers_asg.name 192 | lb_target_group_arn = aws_lb_target_group.external_lb_tg_kubeapi[count.index].arn 193 | } -------------------------------------------------------------------------------- /deployments/README.md: -------------------------------------------------------------------------------- 1 | ## Deploy ECK on Kubernetes 2 | 3 | In this guide we will install [ECK](https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-deploy-eck.html) on Kubernetes. 4 | 5 | First of all install CRDs and ECK operator: 6 | 7 | ``` 8 | kubectl create -f https://download.elastic.co/downloads/eck/2.8.0/crds.yaml 9 | kubectl apply -f https://download.elastic.co/downloads/eck/2.8.0/operator.yaml 10 | ``` 11 | 12 | Then we need to configure our Storage Class ([EFS CSI Driver with dynamic profisioning](https://github.com/kubernetes-sigs/aws-efs-csi-driver)) where elasticsearch will store and persist data: 13 | 14 | ```yaml 15 | --- 16 | kind: StorageClass 17 | apiVersion: storage.k8s.io/v1 18 | metadata: 19 | name: efs-eck-sc # Don't change this name since is used on eck-elastic.yml deloyment 20 | provisioner: efs.csi.aws.com 21 | parameters: 22 | provisioningMode: efs-ap 23 | fileSystemId: # get the id form AWS console 24 | directoryPerms: "755" 25 | basePath: "/eck-storage-dynamic" # optional. Choose an appropriate name 26 | ``` 27 | 28 | Apply the above deployments and then we are ready to deploy elasticsearch: 29 | 30 | ``` 31 | kubectl apply -f https://raw.githubusercontent.com/garutilorenzo/k8s-aws-terraform-cluster/master/deployments/eck-elastic.yml 32 | ``` 33 | 34 | Check the status of the newly created pods, pv and pvc: 35 | 36 | ``` 37 | kubectl get pods 38 | NAME READY STATUS RESTARTS AGE 39 | k8s-eck-es-default-0 0/1 Init:0/2 0 2s 40 | k8s-eck-es-default-1 0/1 Init:0/2 0 2s 41 | k8s-eck-es-default-2 0/1 Init:0/2 0 2s 42 | 43 | root@i-097c1a2b2f1022439:~/eck# kubectl get pv 44 | NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE 45 | pvc-0d766371-f9a4-4210-abe5-077748808643 20Gi RWO Delete Bound default/elasticsearch-data-k8s-eck-es-default-0 efs-eck-sc 34s 46 | pvc-6290aa54-f41b-4705-99fe-f69efddeb168 20Gi RWO Delete Bound default/elasticsearch-data-k8s-eck-es-default-1 efs-eck-sc 34s 47 | pvc-e8e7a076-f8c3-4a93-8239-44b5ca8696fa 20Gi RWO Delete Bound default/elasticsearch-data-k8s-eck-es-default-2 efs-eck-sc 34s 48 | 49 | root@i-097c1a2b2f1022439:~/eck# kubectl get pvc 50 | NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE 51 | elasticsearch-data-k8s-eck-es-default-0 Bound pvc-0d766371-f9a4-4210-abe5-077748808643 20Gi RWO efs-eck-sc 35s 52 | elasticsearch-data-k8s-eck-es-default-1 Bound pvc-6290aa54-f41b-4705-99fe-f69efddeb168 20Gi RWO efs-eck-sc 35s 53 | elasticsearch-data-k8s-eck-es-default-2 Bound pvc-e8e7a076-f8c3-4a93-8239-44b5ca8696fa 20Gi RWO efs-eck-sc 35s 54 | ``` 55 | 56 | Wait until the elasticsearch pods are ready: 57 | 58 | ``` 59 | root@i-097c1a2b2f1022439:~/eck# kubectl get pods 60 | NAME READY STATUS RESTARTS AGE 61 | k8s-eck-es-default-0 1/1 Running 0 3m3s 62 | k8s-eck-es-default-1 1/1 Running 0 3m3s 63 | k8s-eck-es-default-2 1/1 Running 0 3m3s 64 | ``` 65 | 66 | Now we can deploy Kibana with: 67 | 68 | ``` 69 | kubectl apply -f https://raw.githubusercontent.com/garutilorenzo/k8s-aws-terraform-cluster/master/deployments/eck-kibana.yml 70 | ``` 71 | 72 | Wait until kibana is up & running and check for the kibana service name: 73 | 74 | ``` 75 | root@i-097c1a2b2f1022439:~/eck# kubectl get pods 76 | NAME READY STATUS RESTARTS AGE 77 | k8s-eck-es-default-0 1/1 Running 0 9m52s 78 | k8s-eck-es-default-1 1/1 Running 0 9m52s 79 | k8s-eck-es-default-2 1/1 Running 0 9m52s 80 | k8s-eck-kibana-kb-56c4fb4bf8-vc9ct 1/1 Running 0 3m31s 81 | 82 | kubectl get svc 83 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 84 | k8s-eck-es-default ClusterIP None 9200/TCP 9m54s 85 | k8s-eck-es-http ClusterIP 10.107.103.161 9200/TCP 9m55s 86 | k8s-eck-es-internal-http ClusterIP 10.101.251.215 9200/TCP 9m55s 87 | k8s-eck-es-transport ClusterIP None 9300/TCP 9m55s 88 | k8s-eck-kibana-kb-http ClusterIP 10.102.152.26 5601/TCP 3m34s 89 | kubernetes ClusterIP 10.96.0.1 443/TCP 51m 90 | ``` 91 | 92 | Now create an ingress rule with the above deployment and apply it: 93 | 94 | ```yaml 95 | --- 96 | apiVersion: networking.k8s.io/v1 97 | kind: Ingress 98 | metadata: 99 | name: eck-kibana-ingress 100 | annotations: 101 | nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" 102 | spec: 103 | ingressClassName: nginx 104 | rules: 105 | - host: eck.yourdomain.com # FQDN in a domain that you manage. Create a CNAME record that point to the public LB DNS name 106 | http: 107 | paths: 108 | - pathType: Prefix 109 | path: / 110 | backend: 111 | service: 112 | name: k8s-eck-kibana-kb-http 113 | port: 114 | number: 5601 115 | ``` 116 | 117 | Now apply filebeat and metricbeat deployments to get some data into elasticsearch: 118 | 119 | ``` 120 | kubectl apply -f https://raw.githubusercontent.com/garutilorenzo/k8s-aws-terraform-cluster/master/deployments/eck-filebeat.yml 121 | kubectl apply -f https://raw.githubusercontent.com/garutilorenzo/k8s-aws-terraform-cluster/master/deployments/eck-metricbeat.yml 122 | ``` 123 | 124 | And wait that all the pods are ready: 125 | 126 | ``` 127 | root@i-097c1a2b2f1022439:~/eck# kubectl get pods 128 | NAME READY STATUS RESTARTS AGE 129 | k8s-eck-es-default-0 1/1 Running 0 54m 130 | k8s-eck-es-default-1 1/1 Running 0 54m 131 | k8s-eck-es-default-2 1/1 Running 0 54m 132 | k8s-eck-filebeat-beat-filebeat-76s9x 1/1 Running 4 (11m ago) 12m 133 | k8s-eck-filebeat-beat-filebeat-pn77d 1/1 Running 4 (11m ago) 12m 134 | k8s-eck-filebeat-beat-filebeat-wjkhm 1/1 Running 4 (11m ago) 12m 135 | k8s-eck-kibana-kb-77d89694bc-vbp7s 1/1 Running 0 19m 136 | k8s-eck-metricbeat-beat-metricbeat-8kpkl 1/1 Running 1 (7m36s ago) 8m1s 137 | k8s-eck-metricbeat-beat-metricbeat-fl28t 1/1 Running 0 8m1s 138 | k8s-eck-metricbeat-beat-metricbeat-knn2j 1/1 Running 1 (6m16s ago) 8m1s 139 | ``` 140 | 141 | Finally login to the Kibana UI on https://eck.yourdomain.com. Check [here](https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-deploy-kibana.html) how to get the elastic password. -------------------------------------------------------------------------------- /files/install_k8s_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | check_os() { 4 | name=$(cat /etc/os-release | grep ^NAME= | sed 's/"//g') 5 | clean_name=$${name#*=} 6 | 7 | version=$(cat /etc/os-release | grep ^VERSION_ID= | sed 's/"//g') 8 | clean_version=$${version#*=} 9 | major=$${clean_version%.*} 10 | minor=$${clean_version#*.} 11 | 12 | if [[ "$clean_name" == "Ubuntu" ]]; then 13 | operating_system="ubuntu" 14 | elif [[ "$clean_name" == "Amazon Linux" ]]; then 15 | operating_system="amazonlinux" 16 | else 17 | operating_system="undef" 18 | fi 19 | 20 | echo "K3S install process running on: " 21 | echo "OS: $operating_system" 22 | echo "OS Major Release: $major" 23 | echo "OS Minor Release: $minor" 24 | } 25 | 26 | render_config(){ 27 | cat <<-EOF | tee /etc/modules-load.d/containerd.conf 28 | overlay 29 | br_netfilter 30 | EOF 31 | 32 | cat <<-EOF | tee /etc/sysctl.d/99-kubernetes-cri.conf 33 | net.bridge.bridge-nf-call-iptables = 1 34 | net.ipv4.ip_forward = 1 35 | net.bridge.bridge-nf-call-ip6tables = 1 36 | EOF 37 | 38 | modprobe overlay 39 | modprobe br_netfilter 40 | 41 | sudo sysctl --system 42 | } 43 | 44 | preflight(){ 45 | apt-get update && apt-get upgrade -y 46 | 47 | apt-get install -y \ 48 | ca-certificates \ 49 | unzip \ 50 | software-properties-common \ 51 | curl \ 52 | gnupg \ 53 | openssl \ 54 | lsb-release \ 55 | apt-transport-https \ 56 | jq 57 | 58 | render_config 59 | } 60 | 61 | render_containerd_service(){ 62 | cat <<-EOF > /etc/systemd/system/containerd.service 63 | # Copyright The containerd Authors. 64 | # 65 | # Licensed under the Apache License, Version 2.0 (the "License"); 66 | # you may not use this file except in compliance with the License. 67 | # You may obtain a copy of the License at 68 | # 69 | # http://www.apache.org/licenses/LICENSE-2.0 70 | # 71 | # Unless required by applicable law or agreed to in writing, software 72 | # distributed under the License is distributed on an "AS IS" BASIS, 73 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 74 | # See the License for the specific language governing permissions and 75 | # limitations under the License. 76 | [Unit] 77 | Description=containerd container runtime 78 | Documentation=https://containerd.io 79 | After=network.target local-fs.target 80 | [Service] 81 | #uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration 82 | #Environment="ENABLE_CRI_SANDBOXES=sandboxed" 83 | ExecStartPre=-/sbin/modprobe overlay 84 | ExecStart=/usr/local/bin/containerd 85 | Type=notify 86 | Delegate=yes 87 | KillMode=process 88 | Restart=always 89 | RestartSec=5 90 | # Having non-zero Limit*s causes performance problems due to accounting overhead 91 | # in the kernel. We recommend using cgroups to do container-local accounting. 92 | LimitNPROC=infinity 93 | LimitCORE=infinity 94 | LimitNOFILE=infinity 95 | # Comment TasksMax if your systemd version does not supports it. 96 | # Only systemd 226 and above support this version. 97 | TasksMax=infinity 98 | OOMScoreAdjust=-999 99 | [Install] 100 | WantedBy=multi-user.target 101 | EOF 102 | } 103 | 104 | preflight_amz(){ 105 | yum check-update 106 | yum upgrade -y 107 | yum install -y curl unzip jq openssl 108 | 109 | render_config 110 | } 111 | 112 | setup_repos_amz(){ 113 | cat < /dev/null 172 | 173 | curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg 174 | 175 | echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list 176 | 177 | apt-get update 178 | } 179 | 180 | render_crictl_conf(){ 181 | cat <<-EOF | tee /etc/crictl.yaml 182 | --- 183 | runtime-endpoint: unix:///var/run/containerd/containerd.sock 184 | image-endpoint: unix:///var/run/containerd/containerd.sock 185 | EOF 186 | } 187 | 188 | setup_cri(){ 189 | apt-get install -y containerd.io 190 | mkdir -p /etc/containerd 191 | cat /etc/containerd/config.toml | grep -Fx "[grpc]" 192 | res=$? 193 | if [ $res -ne 0 ]; then 194 | containerd config default | tee /etc/containerd/config.toml 195 | fi 196 | sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml 197 | 198 | render_crictl_conf 199 | 200 | systemctl restart containerd 201 | systemctl enable containerd 202 | } 203 | 204 | install_k8s_utils(){ 205 | apt-get install -y kubelet=${k8s_version}* kubeadm=${k8s_version}* kubectl=${k8s_version}* 206 | apt-mark hold kubelet kubeadm kubectl 207 | } 208 | 209 | check_os 210 | 211 | if [[ "$operating_system" == "ubuntu" ]]; then 212 | DEBIAN_FRONTEND=noninteractive 213 | export DEBIAN_FRONTEND 214 | 215 | preflight 216 | install_aws_cli 217 | setup_repos 218 | setup_cri 219 | install_k8s_utils 220 | fi 221 | 222 | if [[ "$operating_system" == "amazonlinux" ]]; then 223 | preflight_amz 224 | setup_repos_amz 225 | setup_cri_amz 226 | install_k8s_utils_amz 227 | fi -------------------------------------------------------------------------------- /iam.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_instance_profile" "k8s_instance_profile" { 2 | name = "${var.common_prefix}-ec2-instance-profile--${var.environment}" 3 | role = aws_iam_role.k8s_iam_role.name 4 | 5 | tags = merge( 6 | local.global_tags, 7 | { 8 | "Name" = lower("${var.common_prefix}-ec2-instance-profile--${var.environment}") 9 | } 10 | ) 11 | } 12 | 13 | resource "aws_iam_role" "k8s_iam_role" { 14 | name = "${var.common_prefix}-iam-role-${var.environment}" 15 | 16 | assume_role_policy = jsonencode({ 17 | Version = "2012-10-17" 18 | Statement = [ 19 | { 20 | Action = "sts:AssumeRole" 21 | Effect = "Allow" 22 | Sid = "" 23 | Principal = { 24 | Service = "ec2.amazonaws.com" 25 | } 26 | }, 27 | ] 28 | }) 29 | 30 | tags = merge( 31 | local.global_tags, 32 | { 33 | "Name" = lower("${var.common_prefix}-iam-role-${var.environment}") 34 | } 35 | ) 36 | } 37 | 38 | resource "aws_iam_policy" "cluster_autoscaler" { 39 | name = "${var.common_prefix}-cluster-autoscaler-policy-${var.environment}" 40 | path = "/" 41 | description = "Cluster autoscaler policy" 42 | 43 | policy = jsonencode({ 44 | Version = "2012-10-17" 45 | Statement = [ 46 | { 47 | Effect = "Allow" 48 | Action = [ 49 | "ec2:DescribeLaunchTemplateVersions" 50 | ], 51 | Resource = [ 52 | "${aws_launch_template.k8s_server.arn}", 53 | "${aws_launch_template.k8s_worker.arn}" 54 | ], 55 | Condition = { 56 | StringEquals = { 57 | for tag, value in local.global_tags : "aws:ResourceTag/${tag}" => value 58 | } 59 | } 60 | }, 61 | { 62 | Effect = "Allow" 63 | Action = [ 64 | "autoscaling:DescribeAutoScalingGroups", 65 | "autoscaling:DescribeAutoScalingInstances", 66 | "autoscaling:DescribeLaunchConfigurations", 67 | "autoscaling:SetDesiredCapacity", 68 | "autoscaling:TerminateInstanceInAutoScalingGroup", 69 | "autoscaling:DescribeTags", 70 | ], 71 | Resource = [ 72 | "${aws_autoscaling_group.k8s_servers_asg.arn}", 73 | "${aws_autoscaling_group.k8s_workers_asg.arn}" 74 | ], 75 | Condition = { 76 | StringEquals = { 77 | for tag, value in local.global_tags : "aws:ResourceTag/${tag}" => value 78 | } 79 | } 80 | }, 81 | ] 82 | }) 83 | 84 | tags = merge( 85 | local.global_tags, 86 | { 87 | "Name" = lower("${var.common_prefix}-cluster-autoscaler-policy-${var.environment}") 88 | } 89 | ) 90 | } 91 | 92 | resource "aws_iam_policy" "aws_efs_csi_driver_policy" { 93 | count = var.efs_persistent_storage ? 1 : 0 94 | name = "${var.common_prefix}-csi-driver-policy-${var.environment}" 95 | path = "/" 96 | description = "AWS EFS CSI driver policy" 97 | 98 | policy = jsonencode({ 99 | Version = "2012-10-17" 100 | Statement = [ 101 | { 102 | Effect = "Allow" 103 | Action = [ 104 | "elasticfilesystem:DescribeAccessPoints", 105 | "elasticfilesystem:DescribeFileSystems", 106 | "elasticfilesystem:DescribeMountTargets", 107 | "ec2:DescribeAvailabilityZones" 108 | ], 109 | Resource = [ 110 | "*" 111 | ] 112 | }, 113 | { 114 | Effect = "Allow" 115 | Action = [ 116 | "elasticfilesystem:CreateAccessPoint" 117 | ], 118 | Resource = [ 119 | "*" 120 | ], 121 | Condition = { 122 | StringLike = { 123 | "aws:RequestTag/efs.csi.aws.com/cluster" = "true" 124 | } 125 | } 126 | }, 127 | { 128 | Effect = "Allow" 129 | Action = [ 130 | "elasticfilesystem:TagResource" 131 | ], 132 | Resource = [ 133 | "*" 134 | ], 135 | Condition = { 136 | StringLike = { 137 | "aws:ResourceTag/efs.csi.aws.com/cluster" = "true" 138 | } 139 | } 140 | }, 141 | { 142 | Effect = "Allow" 143 | Action = [ 144 | "elasticfilesystem:DeleteAccessPoint" 145 | ], 146 | Resource = [ 147 | "*" 148 | ], 149 | Condition = { 150 | StringEquals = { 151 | "aws:ResourceTag/efs.csi.aws.com/cluster" = "true" 152 | } 153 | } 154 | }, 155 | ] 156 | }) 157 | 158 | tags = merge( 159 | local.global_tags, 160 | { 161 | "Name" = lower("${var.common_prefix}-csi-driver-policy-${var.environment}") 162 | } 163 | ) 164 | } 165 | 166 | resource "aws_iam_policy" "allow_secrets_manager" { 167 | name = "${var.common_prefix}-secrets-manager-policy-${var.environment}" 168 | path = "/" 169 | description = "Secrets Manager Policy" 170 | 171 | policy = jsonencode({ 172 | Version = "2012-10-17" 173 | Statement = [ 174 | { 175 | Effect = "Allow" 176 | Action = [ 177 | "secretsmanager:GetSecretValue", 178 | "secretsmanager:UpdateSecret", 179 | "secretsmanager:DeleteSecret", 180 | "secretsmanager:DescribeSecret", 181 | "secretsmanager:ListSecrets", 182 | "secretsmanager:CreateSecret", 183 | "secretsmanager:PutSecretValue" 184 | ], 185 | Resource = [ 186 | "${aws_secretsmanager_secret.kubeconfig_secret.arn}", 187 | "${aws_secretsmanager_secret.kubeadm_ca.arn}", 188 | "${aws_secretsmanager_secret.kubeadm_token.arn}", 189 | "${aws_secretsmanager_secret.kubeadm_cert.arn}" 190 | ], 191 | Condition = { 192 | StringEquals = { 193 | for tag, value in local.global_tags : "aws:ResourceTag/${tag}" => value 194 | } 195 | } 196 | }, 197 | { 198 | Effect = "Allow" 199 | Action = [ 200 | "secretsmanager:ListSecrets" 201 | ], 202 | Resource = [ 203 | "*" 204 | ], 205 | } 206 | ] 207 | }) 208 | 209 | tags = merge( 210 | local.global_tags, 211 | { 212 | "Name" = lower("${var.common_prefix}-secrets-manager-policy-${var.environment}") 213 | } 214 | ) 215 | } 216 | 217 | resource "aws_iam_role_policy_attachment" "attach_ssm_policy" { 218 | role = aws_iam_role.k8s_iam_role.name 219 | policy_arn = data.aws_iam_policy.AmazonSSMManagedInstanceCore.arn 220 | } 221 | 222 | resource "aws_iam_role_policy_attachment" "attach_cluster_autoscaler_policy" { 223 | role = aws_iam_role.k8s_iam_role.name 224 | policy_arn = aws_iam_policy.cluster_autoscaler.arn 225 | } 226 | 227 | resource "aws_iam_role_policy_attachment" "attach_aws_efs_csi_driver_policy" { 228 | count = var.efs_persistent_storage ? 1 : 0 229 | role = aws_iam_role.k8s_iam_role.name 230 | policy_arn = aws_iam_policy.aws_efs_csi_driver_policy[0].arn 231 | } 232 | 233 | resource "aws_iam_role_policy_attachment" "attach_allow_secrets_manager_policy" { 234 | role = aws_iam_role.k8s_iam_role.name 235 | policy_arn = aws_iam_policy.allow_secrets_manager.arn 236 | } 237 | 238 | resource "aws_iam_role_policy_attachment" "attach_ec2_ro_policy" { 239 | role = aws_iam_role.k8s_iam_role.name 240 | policy_arn = data.aws_iam_policy.AmazonEC2ReadOnlyAccess.arn 241 | } -------------------------------------------------------------------------------- /files/install_k8s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | render_kubeinit(){ 4 | 5 | HOSTNAME=$(hostname) 6 | ADVERTISE_ADDR=$(ip -o route get to 8.8.8.8 | grep -Po '(?<=src )(\S+)') 7 | 8 | cat <<-EOF > /root/kubeadm-init-config.yaml 9 | --- 10 | apiVersion: kubeadm.k8s.io/v1beta3 11 | bootstrapTokens: 12 | - groups: 13 | - system:bootstrappers:kubeadm:default-node-token 14 | token: abcdef.0123456789abcdef 15 | ttl: 24h0m0s 16 | usages: 17 | - signing 18 | - authentication 19 | kind: InitConfiguration 20 | localAPIEndpoint: 21 | advertiseAddress: $ADVERTISE_ADDR 22 | bindPort: ${kube_api_port} 23 | nodeRegistration: 24 | criSocket: /run/containerd/containerd.sock 25 | imagePullPolicy: IfNotPresent 26 | name: $HOSTNAME 27 | taints: null 28 | --- 29 | apiServer: 30 | timeoutForControlPlane: 4m0s 31 | certSANs: 32 | - $HOSTNAME 33 | - $ADVERTISE_ADDR 34 | %{~ if expose_kubeapi ~} 35 | - ${k8s_tls_san_public} 36 | %{~ endif ~} 37 | apiVersion: kubeadm.k8s.io/v1beta3 38 | certificatesDir: /etc/kubernetes/pki 39 | clusterName: kubernetes 40 | controllerManager: {} 41 | dns: {} 42 | imageRepository: registry.k8s.io 43 | kind: ClusterConfiguration 44 | kubernetesVersion: ${k8s_version} 45 | controlPlaneEndpoint: ${control_plane_url}:${kube_api_port} 46 | networking: 47 | dnsDomain: ${k8s_dns_domain} 48 | podSubnet: ${k8s_pod_subnet} 49 | serviceSubnet: ${k8s_service_subnet} 50 | scheduler: {} 51 | etcd: 52 | local: 53 | dataDir: /var/lib/etcd 54 | --- 55 | kind: KubeletConfiguration 56 | apiVersion: kubelet.config.k8s.io/v1beta1 57 | cgroupDriver: systemd 58 | EOF 59 | } 60 | 61 | wait_lb() { 62 | while [ true ] 63 | do 64 | curl --output /dev/null --silent -k https://${control_plane_url}:${kube_api_port} 65 | if [[ "$?" -eq 0 ]]; then 66 | break 67 | fi 68 | sleep 5 69 | echo "wait for LB" 70 | done 71 | } 72 | 73 | wait_for_ca_secret(){ 74 | res_ca=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 75 | while [[ -z "$res_ca" || "$res_ca" == "${default_secret_placeholder}" ]] 76 | do 77 | echo "Waiting the ca hash ..." 78 | res_ca=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 79 | sleep 1 80 | done 81 | 82 | res_cert=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_cert_secret_name} | jq -r .SecretString) 83 | while [[ -z "$res_cert" || "$res_cert" == "${default_secret_placeholder}" ]] 84 | do 85 | echo "Waiting the ca hash ..." 86 | res_cert=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_cert_secret_name} | jq -r .SecretString) 87 | sleep 1 88 | done 89 | 90 | res_token=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 91 | while [[ -z "$res_token" || "$res_token" == "${default_secret_placeholder}" ]] 92 | do 93 | echo "Waiting the ca hash ..." 94 | res_token=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 95 | sleep 1 96 | done 97 | } 98 | 99 | wait_for_pods(){ 100 | until kubectl get pods -A | grep 'Running'; do 101 | echo 'Waiting for k8s startup' 102 | sleep 5 103 | done 104 | } 105 | 106 | wait_for_masters(){ 107 | until kubectl get nodes -o wide | grep 'control-plane'; do 108 | echo 'Waiting for k8s control-planes' 109 | sleep 5 110 | done 111 | } 112 | 113 | setup_env(){ 114 | until [ -f /etc/kubernetes/admin.conf ] 115 | do 116 | sleep 5 117 | done 118 | echo "K8s initialized" 119 | export KUBECONFIG=/etc/kubernetes/admin.conf 120 | } 121 | 122 | render_kubejoin(){ 123 | 124 | HOSTNAME=$(hostname) 125 | ADVERTISE_ADDR=$(ip -o route get to 8.8.8.8 | grep -Po '(?<=src )(\S+)') 126 | CA_HASH=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 127 | KUBEADM_CERT=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_cert_secret_name} | jq -r .SecretString) 128 | KUBEADM_TOKEN=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_token_secret_name} | jq -r .SecretString) 129 | 130 | cat <<-EOF > /root/kubeadm-join-master.yaml 131 | --- 132 | apiVersion: kubeadm.k8s.io/v1beta3 133 | kind: JoinConfiguration 134 | discovery: 135 | bootstrapToken: 136 | token: $KUBEADM_TOKEN 137 | apiServerEndpoint: ${control_plane_url}:${kube_api_port} 138 | caCertHashes: 139 | - sha256:$CA_HASH 140 | controlPlane: 141 | localAPIEndpoint: 142 | advertiseAddress: $ADVERTISE_ADDR 143 | bindPort: ${kube_api_port} 144 | certificateKey: $KUBEADM_CERT 145 | nodeRegistration: 146 | criSocket: /run/containerd/containerd.sock 147 | imagePullPolicy: IfNotPresent 148 | name: $HOSTNAME 149 | taints: null 150 | --- 151 | kind: KubeletConfiguration 152 | apiVersion: kubelet.config.k8s.io/v1beta1 153 | cgroupDriver: systemd 154 | EOF 155 | } 156 | 157 | render_nginx_config(){ 158 | cat << 'EOF' > "$NGINX_RESOURCES_FILE" 159 | --- 160 | apiVersion: v1 161 | kind: Service 162 | metadata: 163 | name: ingress-nginx-controller 164 | namespace: ingress-nginx 165 | spec: 166 | ports: 167 | - appProtocol: http 168 | name: http 169 | port: 80 170 | protocol: TCP 171 | targetPort: http 172 | nodePort: ${extlb_listener_http_port} 173 | - appProtocol: https 174 | name: https 175 | port: 443 176 | protocol: TCP 177 | targetPort: https 178 | nodePort: ${extlb_listener_https_port} 179 | selector: 180 | app.kubernetes.io/component: controller 181 | app.kubernetes.io/instance: ingress-nginx 182 | app.kubernetes.io/name: ingress-nginx 183 | type: NodePort 184 | --- 185 | apiVersion: v1 186 | data: 187 | allow-snippet-annotations: "true" 188 | enable-real-ip: "true" 189 | proxy-real-ip-cidr: "0.0.0.0/0" 190 | proxy-body-size: "20m" 191 | use-proxy-protocol: "true" 192 | kind: ConfigMap 193 | metadata: 194 | labels: 195 | app.kubernetes.io/component: controller 196 | app.kubernetes.io/instance: ingress-nginx 197 | app.kubernetes.io/name: ingress-nginx 198 | app.kubernetes.io/part-of: ingress-nginx 199 | app.kubernetes.io/version: ${nginx_ingress_release} 200 | name: ingress-nginx-controller 201 | namespace: ingress-nginx 202 | EOF 203 | } 204 | 205 | install_and_configure_nginx(){ 206 | kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-${nginx_ingress_release}/deploy/static/provider/baremetal/deploy.yaml 207 | NGINX_RESOURCES_FILE=/root/nginx-ingress-resources.yaml 208 | render_nginx_config 209 | kubectl apply -f $NGINX_RESOURCES_FILE 210 | } 211 | 212 | render_staging_issuer(){ 213 | STAGING_ISSUER_RESOURCE=$1 214 | cat << 'EOF' > "$STAGING_ISSUER_RESOURCE" 215 | apiVersion: cert-manager.io/v1 216 | kind: ClusterIssuer 217 | metadata: 218 | name: letsencrypt-staging 219 | namespace: cert-manager 220 | spec: 221 | acme: 222 | # The ACME server URL 223 | server: https://acme-staging-v02.api.letsencrypt.org/directory 224 | # Email address used for ACME registration 225 | email: ${certmanager_email_address} 226 | # Name of a secret used to store the ACME account private key 227 | privateKeySecretRef: 228 | name: letsencrypt-staging 229 | # Enable the HTTP-01 challenge provider 230 | solvers: 231 | - http01: 232 | ingress: 233 | class: nginx 234 | EOF 235 | } 236 | 237 | render_prod_issuer(){ 238 | PROD_ISSUER_RESOURCE=$1 239 | cat << 'EOF' > "$PROD_ISSUER_RESOURCE" 240 | apiVersion: cert-manager.io/v1 241 | kind: ClusterIssuer 242 | metadata: 243 | name: letsencrypt-prod 244 | namespace: cert-manager 245 | spec: 246 | acme: 247 | # The ACME server URL 248 | server: https://acme-v02.api.letsencrypt.org/directory 249 | # Email address used for ACME registration 250 | email: ${certmanager_email_address} 251 | # Name of a secret used to store the ACME account private key 252 | privateKeySecretRef: 253 | name: letsencrypt-prod 254 | # Enable the HTTP-01 challenge provider 255 | solvers: 256 | - http01: 257 | ingress: 258 | class: nginx 259 | EOF 260 | } 261 | 262 | install_and_configure_certmanager(){ 263 | kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${certmanager_release}/cert-manager.yaml 264 | render_staging_issuer /root/staging_issuer.yaml 265 | render_prod_issuer /root/prod_issuer.yaml 266 | 267 | # Wait cert-manager to be ready 268 | until kubectl get pods -n cert-manager | grep 'Running'; do 269 | echo 'Waiting for cert-manager to be ready' 270 | sleep 15 271 | done 272 | 273 | kubectl create -f /root/prod_issuer.yaml 274 | kubectl create -f /root/staging_issuer.yaml 275 | } 276 | 277 | install_and_configure_csi_driver(){ 278 | git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git 279 | cd aws-efs-csi-driver/ 280 | git checkout tags/${efs_csi_driver_release} -b kube_deploy_${efs_csi_driver_release} 281 | kubectl apply -k deploy/kubernetes/overlays/stable/ 282 | 283 | # Uncomment this to mount the EFS share on the first k8s-server node 284 | # mkdir /efs 285 | # aws_region="$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)" 286 | # mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${efs_filesystem_id}.efs.$aws_region.amazonaws.com:/ /efs 287 | } 288 | 289 | k8s_join(){ 290 | kubeadm join --config /root/kubeadm-join-master.yaml 291 | mkdir ~/.kube 292 | cp /etc/kubernetes/admin.conf ~/.kube/config 293 | 294 | # Upload kubeconfig on AWS secret manager 295 | cat ~/.kube/config | sed 's/server: https:\/\/127.0.0.1:6443/server: https:\/\/${control_plane_url}:${kube_api_port}/' > /root/kube.conf 296 | aws secretsmanager update-secret --secret-id ${kubeconfig_secret_name} --secret-string file:///root/kube.conf 297 | } 298 | 299 | wait_for_secretsmanager(){ 300 | res=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 301 | while [[ -z "$res" ]] 302 | do 303 | echo "Waiting the ca hash ..." 304 | res=$(aws secretsmanager get-secret-value --secret-id ${kubeadm_ca_secret_name} | jq -r .SecretString) 305 | sleep 1 306 | done 307 | } 308 | 309 | generate_secrets(){ 310 | wait_for_secretsmanager 311 | HASH=$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //') 312 | echo $HASH > /tmp/ca.txt 313 | 314 | TOKEN=$(kubeadm token create) 315 | echo $TOKEN > /tmp/kubeadm_token.txt 316 | 317 | CERT=$(kubeadm init phase upload-certs --upload-certs | tail -n 1) 318 | echo $CERT > /tmp/kubeadm_cert.txt 319 | 320 | aws secretsmanager update-secret --secret-id ${kubeadm_ca_secret_name} --secret-string file:///tmp/ca.txt 321 | aws secretsmanager update-secret --secret-id ${kubeadm_cert_secret_name} --secret-string file:///tmp/kubeadm_cert.txt 322 | aws secretsmanager update-secret --secret-id ${kubeadm_token_secret_name} --secret-string file:///tmp/kubeadm_token.txt 323 | } 324 | 325 | k8s_init(){ 326 | kubeadm init --config /root/kubeadm-init-config.yaml 327 | mkdir ~/.kube 328 | cp /etc/kubernetes/admin.conf ~/.kube/config 329 | } 330 | 331 | setup_cni(){ 332 | until kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml; do 333 | echo "Trying to install CNI flannel" 334 | done 335 | } 336 | 337 | first_instance=$(aws ec2 describe-instances --filters Name=tag-value,Values=k8s-server Name=instance-state-name,Values=running --query 'sort_by(Reservations[].Instances[], &LaunchTime)[:-1].[InstanceId]' --output text | head -n1) 338 | instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) 339 | 340 | if [[ "$first_instance" == "$instance_id" ]]; then 341 | render_kubeinit 342 | k8s_init 343 | setup_env 344 | wait_for_pods 345 | setup_cni 346 | generate_secrets 347 | echo "Wait 180 seconds for control-planes to join" 348 | sleep 180 349 | wait_for_masters 350 | %{ if install_nginx_ingress } 351 | install_and_configure_nginx 352 | %{ endif } 353 | %{ if install_certmanager } 354 | install_and_configure_certmanager 355 | %{ endif } 356 | %{ if efs_persistent_storage } 357 | install_and_configure_csi_driver 358 | %{ endif } 359 | %{ if install_node_termination_handler } 360 | #Install node termination handler 361 | echo 'Install node termination handler' 362 | kubectl apply -f https://github.com/aws/aws-node-termination-handler/releases/download/${node_termination_handler_release}/all-resources.yaml 363 | %{ endif } 364 | else 365 | wait_for_ca_secret 366 | render_kubejoin 367 | wait_lb 368 | k8s_join 369 | fi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/k8s-aws-terraform-cluster)](https://github.com/garutilorenzo/k8s-aws-terraform-cluster/issues) 2 | ![GitHub](https://img.shields.io/github/license/garutilorenzo/k8s-aws-terraform-cluster) 3 | [![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/k8s-aws-terraform-cluster)](https://github.com/garutilorenzo/k8s-aws-terraform-cluster/network) 4 | [![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/k8s-aws-terraform-cluster)](https://github.com/garutilorenzo/k8s-aws-terraform-cluster/stargazers) 5 | 6 |

7 | k8s Logo 8 |

9 | 10 | # Deploy Kubernetes on Amazon AWS 11 | 12 | Deploy in a few minutes an high available Kubernetes cluster on Amazon AWS using mixed on-demand and spot instances. 13 | 14 | Please **note**, this is only an example on how to Deploy a Kubernetes cluster. For a production environment you should use [EKS](https://aws.amazon.com/eks/) or [ECS](https://aws.amazon.com/it/ecs/). 15 | 16 | The scope of this repo is to show all the AWS components needed to deploy a high available K8s cluster. 17 | 18 | # Table of Contents 19 | 20 | - [Deploy Kubernetes on Amazon AWS](#deploy-kubernetes-on-amazon-aws) 21 | - [Table of Contents](#table-of-contents) 22 | - [Requirements](#requirements) 23 | - [Before you start](#before-you-start) 24 | - [Project setup](#project-setup) 25 | - [AWS provider setup](#aws-provider-setup) 26 | - [Pre flight checklist](#pre-flight-checklist) 27 | - [Infrastructure overview](#infrastructure-overview) 28 | - [Kubernetes setup](#kubernetes-setup) 29 | - [Nginx ingress controller](#nginx-ingress-controller) 30 | - [Cert manager](#cert-manager) 31 | - [Deploy](#deploy) 32 | - [Public LB check](#public-lb-check) 33 | - [Deploy a sample stack](#deploy-a-sample-stack) 34 | - [Clean up](#clean-up) 35 | - [Todo](#todo) 36 | 37 | ## Requirements 38 | 39 | * [Terraform](https://www.terraform.io/) - Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files. 40 | * [Amazon AWS Account](https://aws.amazon.com/it/console/) - Amazon AWS account with billing enabled 41 | * [kubectl](https://kubernetes.io/docs/tasks/tools/) - The Kubernetes command-line tool (optional) 42 | * [aws cli](https://aws.amazon.com/cli/) optional 43 | 44 | You need also: 45 | 46 | * one VPC with private and public subnets 47 | * one ssh key already uploaded on your AWS account 48 | 49 | For VPC you can refer to [this](https://github.com/garutilorenzo/aws-terraform-examples) repository. 50 | 51 | ## Before you start 52 | 53 | Note that this tutorial uses AWS resources that are outside the AWS free tier, so be careful! 54 | 55 | ## Project setup 56 | 57 | Clone this repo and go in the example/ directory: 58 | 59 | ``` 60 | git clone https://github.com/garutilorenzo/k8s-aws-terraform-cluster 61 | cd k8s-aws-terraform-cluster/example/ 62 | ``` 63 | 64 | Now you have to edit the `main.tf` file and you have to create the `terraform.tfvars` file. For more detail see [AWS provider setup](#aws-provider-setup) and [Pre flight checklist](#pre-flight-checklist). 65 | 66 | Or if you prefer you can create an new empty directory in your workspace and create this three files: 67 | 68 | * `terraform.tfvars` 69 | * `main.tf` 70 | * `provider.tf` 71 | 72 | The main.tf file will look like: 73 | 74 | ``` 75 | variable "AWS_ACCESS_KEY" { 76 | 77 | } 78 | 79 | variable "AWS_SECRET_KEY" { 80 | 81 | } 82 | 83 | variable "environment" { 84 | default = "staging" 85 | } 86 | 87 | variable "AWS_REGION" { 88 | default = "" 89 | } 90 | 91 | variable "my_public_ip_cidr" { 92 | default = "" 93 | } 94 | 95 | variable "vpc_cidr_block" { 96 | default = "" 97 | } 98 | 99 | variable "certmanager_email_address" { 100 | default = "" 101 | } 102 | 103 | variable "ssk_key_pair_name" { 104 | default = "" 105 | } 106 | 107 | module "private-vpc" { 108 | region = var.AWS_REGION 109 | my_public_ip_cidr = var.my_public_ip_cidr 110 | vpc_cidr_block = var.vpc_cidr_block 111 | environment = var.environment 112 | source = "github.com/garutilorenzo/aws-terraform-examples/private-vpc" 113 | } 114 | 115 | output "private_subnets_ids" { 116 | value = module.private-vpc.private_subnet_ids 117 | } 118 | 119 | output "public_subnets_ids" { 120 | value = module.private-vpc.public_subnet_ids 121 | } 122 | 123 | output "vpc_id" { 124 | value = module.private-vpc.vpc_id 125 | } 126 | 127 | module "k8s-cluster" { 128 | ssk_key_pair_name = var.ssk_key_pair_name 129 | environment = var.environment 130 | vpc_id = module.private-vpc.vpc_id 131 | vpc_private_subnets = module.private-vpc.private_subnet_ids 132 | vpc_public_subnets = module.private-vpc.public_subnet_ids 133 | vpc_subnet_cidr = var.vpc_cidr_block 134 | my_public_ip_cidr = var.my_public_ip_cidr 135 | create_extlb = true 136 | install_nginx_ingress = true 137 | efs_persistent_storage = true 138 | expose_kubeapi = true 139 | install_certmanager = true 140 | certmanager_email_address = var.certmanager_email_address 141 | source = "github.com/garutilorenzo/k8s-aws-terraform-cluster" 142 | } 143 | 144 | output "k8s_dns_name" { 145 | value = module.k8s-cluster.k8s_dns_name 146 | } 147 | 148 | output "k8s_server_private_ips" { 149 | value = module.k8s-cluster.k8s_server_private_ips 150 | } 151 | 152 | output "k8s_workers_private_ips" { 153 | value = module.k8s-cluster.k8s_workers_private_ips 154 | } 155 | ``` 156 | 157 | For all the possible variables see [Pre flight checklist](#pre-flight-checklist) 158 | 159 | The `provider.tf` will look like: 160 | 161 | ``` 162 | provider "aws" { 163 | region = var.AWS_REGION 164 | access_key = var.AWS_ACCESS_KEY 165 | secret_key = var.AWS_SECRET_KEY 166 | } 167 | ``` 168 | 169 | The `terraform.tfvars` will look like: 170 | 171 | ``` 172 | AWS_ACCESS_KEY = "xxxxxxxxxxxxxxxxx" 173 | AWS_SECRET_KEY = "xxxxxxxxxxxxxxxxx" 174 | ``` 175 | 176 | Now we can init terraform with: 177 | 178 | ``` 179 | terraform init 180 | 181 | Initializing modules... 182 | - k8s-cluster in .. 183 | 184 | Initializing the backend... 185 | 186 | Initializing provider plugins... 187 | - Finding latest version of hashicorp/template... 188 | - Finding latest version of hashicorp/aws... 189 | - Installing hashicorp/template v2.2.0... 190 | - Installed hashicorp/template v2.2.0 (signed by HashiCorp) 191 | - Installing hashicorp/aws v4.9.0... 192 | - Installed hashicorp/aws v4.9.0 (signed by HashiCorp) 193 | 194 | Terraform has created a lock file .terraform.lock.hcl to record the provider 195 | selections it made above. Include this file in your version control repository 196 | so that Terraform can guarantee to make the same selections by default when 197 | you run "terraform init" in the future. 198 | 199 | Terraform has been successfully initialized! 200 | 201 | You may now begin working with Terraform. Try running "terraform plan" to see 202 | any changes that are required for your infrastructure. All Terraform commands 203 | should now work. 204 | 205 | If you ever set or change modules or backend configuration for Terraform, 206 | rerun this command to reinitialize your working directory. If you forget, other 207 | commands will detect it and remind you to do so if necessary. 208 | ``` 209 | 210 | ## AWS provider setup 211 | 212 | Follow the prerequisites step on [this](https://learn.hashicorp.com/tutorials/terraform/aws-build?in=terraform/aws-get-started) link. 213 | In your workspace folder or in the examples directory of this repo create a file named `terraform.tfvars`: 214 | 215 | ``` 216 | AWS_ACCESS_KEY = "xxxxxxxxxxxxxxxxx" 217 | AWS_SECRET_KEY = "xxxxxxxxxxxxxxxxx" 218 | ``` 219 | 220 | ## Pre flight checklist 221 | 222 | Once you have created the `terraform.tfvars` file edit the `main.tf` file (always in the example/ directory) and set the following variables: 223 | 224 | | Var | Required | Desc | 225 | | ------- | ------- | ----------- | 226 | | `region` | `yes` | set the correct AWS region based on your needs | 227 | | `environment` | `yes` | Current work environment (Example: staging/dev/prod). This value is used for tag all the deployed resources | 228 | | `ssk_key_pair_name` | `yes` | Name of the ssh key to use | 229 | | `my_public_ip_cidr` | `yes` | your public ip in cidr format (Example: 195.102.xxx.xxx/32) | 230 | | `vpc_id` | `yes` | ID of the VPC to use. You can find your vpc_id in your AWS console (Example: vpc-xxxxx) | 231 | | `vpc_private_subnets` | `yes` | List of private subnets to use. This subnets are used for the public LB You can find the list of your vpc subnets in your AWS console (Example: subnet-xxxxxx) | 232 | | `vpc_public_subnets` | `yes` | List of public subnets to use. This subnets are used for the EC2 instances and the private LB. You can find the list of your vpc subnets in your AWS console (Example: subnet-xxxxxx) | 233 | | `vpc_subnet_cidr` | `yes` | Your subnet CIDR. You can find the VPC subnet CIDR in your AWS console (Example: 172.31.0.0/16) | 234 | | `common_prefix` | `no` | Prefix used in all resource names/tags. Default: k8s | 235 | | `ec2_associate_public_ip_address` | `no` | Assign or not a pulic ip to the EC2 instances. Default: false | 236 | | `instance_profile_name` | `no` | Instance profile name. Default: K8sInstanceProfile | 237 | | `ami` | `no` | Ami image name. Default: ami-0a2616929f1e63d91, ubuntu 20.04 | 238 | | `default_instance_type` | `no` | Default instance type used by the Launch template. Default: t3.large | 239 | | `instance_types` | `no` | Array of instances used by the ASG. Dfault: { asg_instance_type_1 = "t3.large", asg_instance_type_3 = "m4.large", asg_instance_type_4 = "t3a.large" } | 240 | | `k8s_version` | `no` | Kubernetes version to install | 241 | | `k8s_pod_subnet` | `no` | Kubernetes pod subnet managed by the CNI (Flannel). Default: 10.244.0.0/16 | 242 | | `k8s_service_subnet` | `no` | Kubernetes pod service managed by the CNI (Flannel). Default: 10.96.0.0/12 | 243 | | `k8s_dns_domain` | `no` | Internal kubernetes DNS domain. Default: cluster.local | 244 | | `kube_api_port` | `no` | Kubernetes api port. Default: 6443 | 245 | | `k8s_server_desired_capacity` | `no` | Desired number of k8s servers. Default 3 | 246 | | `k8s_server_min_capacity` | `no` | Min number of k8s servers: Default 4 | 247 | | `k8s_server_max_capacity` | `no` | Max number of k8s servers: Default 3 | 248 | | `k8s_worker_desired_capacity` | `no` | Desired number of k8s workers. Default 3 | 249 | | `k8s_worker_min_capacity` | `no` | Min number of k8s workers: Default 4 | 250 | | `k8s_worker_max_capacity` | `no` | Max number of k8s workers: Default 3 | 251 | | `cluster_name` | `no` | Kubernetes cluster name. Default: k8s-cluster | 252 | | `install_nginx_ingress` | `no` | Install or not nginx ingress controller. Default: false | 253 | | `nginx_ingress_release` | `no` | Nginx ingress release to install. Default: v1.8.1| 254 | | `install_certmanager` | `no` | Boolean value, install [cert manager](https://cert-manager.io/) "Cloud native certificate management". Default: true | 255 | | `certmanager_email_address` | `no` | Email address used for signing https certificates. Defaul: changeme@example.com | 256 | | `certmanager_release` | `no` | Cert manager release. Default: v1.12.2 | 257 | | `efs_persistent_storage` | `no` | Deploy EFS for persistent sotrage | 258 | | `efs_csi_driver_release` | `no` | EFS CSI driver Release: v1.5.8 | 259 | | `extlb_listener_http_port` | `no` | HTTP nodeport where nginx ingress controller will listen. Default: 30080 | 260 | | `extlb_listener_https_port` | `no` | HTTPS nodeport where nginx ingress controller will listen. Default 30443 | 261 | | `extlb_http_port` | `no` | External LB HTTP listen port. Default: 80 | 262 | | `extlb_https_port` | `no` | External LB HTTPS listen port. Default 443 | 263 | | `expose_kubeapi` | `no` | Boolean value, default false. Expose or not the kubeapi server to the internet. Access is granted only from *my_public_ip_cidr* for security reasons. | 264 | 265 | ## Infrastructure overview 266 | 267 | The final infrastructure will be made by: 268 | 269 | * two autoscaling group, one for the kubernetes master nodes and one for the worker nodes 270 | * two launch template, used by the asg 271 | * one internal load balancer (L4) that will route traffic to Kubernetes servers 272 | * one external load balancer (L4) that will route traffic to Kubernetes workers 273 | * one security group that will allow traffic from the VPC subnet CIDR on all the k8s ports (kube api, nginx ingress node port etc) 274 | * one security group that will allow traffic from all the internet into the public load balancer (L4) on port 80 and 443 275 | * four secrets that will store k8s join tokens 276 | 277 | Optional resources: 278 | 279 | * EFS storage to persist data 280 | 281 | ## Kubernetes setup 282 | 283 | The installation of K8s id done by [kubeadm](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/). In this installation [Containerd](https://containerd.io/) is used as CRI and [flannel](https://github.com/flannel-io/flannel) is used as CNI. 284 | 285 | You can optionally install [Nginx ingress controller](https://kubernetes.github.io/ingress-nginx/). 286 | 287 | To install Nginx ingress set the variable *install_nginx_ingress* to yes (default no). 288 | 289 | ### Nginx ingress controller 290 | 291 | You can optionally install [Nginx ingress controller](https://kubernetes.github.io/ingress-nginx/) To enable the Nginx deployment set `install_nginx_ingress` variable to `true`. 292 | 293 | The installation is the [bare metal](https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal-clusters) installation, the ingress controller then is exposed via a NodePort Service. 294 | 295 | ```yaml 296 | --- 297 | apiVersion: v1 298 | kind: Service 299 | metadata: 300 | name: ingress-nginx-controller 301 | namespace: ingress-nginx 302 | spec: 303 | ports: 304 | - appProtocol: http 305 | name: http 306 | port: 80 307 | protocol: TCP 308 | targetPort: http 309 | nodePort: ${extlb_listener_http_port} 310 | - appProtocol: https 311 | name: https 312 | port: 443 313 | protocol: TCP 314 | targetPort: https 315 | nodePort: ${extlb_listener_https_port} 316 | selector: 317 | app.kubernetes.io/component: controller 318 | app.kubernetes.io/instance: ingress-nginx 319 | app.kubernetes.io/name: ingress-nginx 320 | type: NodePort 321 | ``` 322 | 323 | To get the real ip address of the clients using a public L4 load balancer we need to use the proxy protocol feature of nginx ingress controller: 324 | 325 | ```yaml 326 | --- 327 | apiVersion: v1 328 | data: 329 | allow-snippet-annotations: "true" 330 | enable-real-ip: "true" 331 | proxy-real-ip-cidr: "0.0.0.0/0" 332 | proxy-body-size: "20m" 333 | use-proxy-protocol: "true" 334 | kind: ConfigMap 335 | metadata: 336 | labels: 337 | app.kubernetes.io/component: controller 338 | app.kubernetes.io/instance: ingress-nginx 339 | app.kubernetes.io/name: ingress-nginx 340 | app.kubernetes.io/part-of: ingress-nginx 341 | app.kubernetes.io/version: ${nginx_ingress_release} 342 | name: ingress-nginx-controller 343 | namespace: ingress-nginx 344 | ``` 345 | 346 | ### Cert-manager 347 | 348 | [cert-manager](https://cert-manager.io/docs/) is used to issue certificates from a variety of supported source. 349 | 350 | ## Deploy 351 | 352 | We are now ready to deploy our infrastructure. First we ask terraform to plan the execution with: 353 | 354 | ``` 355 | terraform plan 356 | 357 | ... 358 | ... 359 | Plan: 73 to add, 0 to change, 0 to destroy. 360 | 361 | Changes to Outputs: 362 | + k8s_dns_name = [ 363 | + (known after apply), 364 | ] 365 | ~ k8s_server_private_ips = [ 366 | - [], 367 | + (known after apply), 368 | ] 369 | ~ k8s_workers_private_ips = [ 370 | - [], 371 | + (known after apply), 372 | ] 373 | + private_subnets_ids = [ 374 | + (known after apply), 375 | + (known after apply), 376 | + (known after apply), 377 | ] 378 | + public_subnets_ids = [ 379 | + (known after apply), 380 | + (known after apply), 381 | + (known after apply), 382 | ] 383 | + vpc_id = (known after apply) 384 | 385 | ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 386 | 387 | Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. 388 | ``` 389 | 390 | now we can deploy our resources with: 391 | 392 | ``` 393 | terraform apply 394 | 395 | ... 396 | 397 | Plan: 73 to add, 0 to change, 0 to destroy. 398 | 399 | Changes to Outputs: 400 | + k8s_dns_name = [ 401 | + (known after apply), 402 | ] 403 | ~ k8s_server_private_ips = [ 404 | - [], 405 | + (known after apply), 406 | ] 407 | ~ k8s_workers_private_ips = [ 408 | - [], 409 | + (known after apply), 410 | ] 411 | + private_subnets_ids = [ 412 | + (known after apply), 413 | + (known after apply), 414 | + (known after apply), 415 | ] 416 | + public_subnets_ids = [ 417 | + (known after apply), 418 | + (known after apply), 419 | + (known after apply), 420 | ] 421 | + vpc_id = (known after apply) 422 | 423 | Do you want to perform these actions? 424 | Terraform will perform the actions described above. 425 | Only 'yes' will be accepted to approve. 426 | 427 | Enter a value: yes 428 | 429 | ... 430 | ... 431 | 432 | Apply complete! Resources: 73 added, 0 changed, 0 destroyed. 433 | 434 | Outputs: 435 | 436 | k8s_dns_name = "k8s-ext-.elb.amazonaws.com" 437 | k8s_server_private_ips = [ 438 | tolist([ 439 | "172.x.x.x", 440 | "172.x.x.x", 441 | "172.x.x.x", 442 | ]), 443 | ] 444 | k8s_workers_private_ips = [ 445 | tolist([ 446 | "172.x.x.x", 447 | "172.x.x.x", 448 | "172.x.x.x", 449 | ]), 450 | ] 451 | private_subnets_ids = [ 452 | "subnet-xxxxxxxxxxxxxxxxx", 453 | "subnet-xxxxxxxxxxxxxxxxx", 454 | "subnet-xxxxxxxxxxxxxxxxx", 455 | ] 456 | public_subnets_ids = [ 457 | "subnet-xxxxxxxxxxxxxxxxx", 458 | "subnet-xxxxxxxxxxxxxxxxx", 459 | "subnet-xxxxxxxxxxxxxxxxx", 460 | ] 461 | vpc_id = "vpc-xxxxxxxxxxxxxxxxx" 462 | ``` 463 | Now on one master node (connect via AWS SSM) you can check the status of the cluster with: 464 | 465 | ``` 466 | ubuntu@i-04d089ed896cfafe1:~$ sudo su - 467 | 468 | root@i-04d089ed896cfafe1:~# kubectl get nodes 469 | NAME STATUS ROLES AGE VERSION 470 | i-0033b408f7a1d55f3 Ready control-plane,master 3m33s v1.23.5 471 | i-0121c2149821379cc Ready 4m16s v1.23.5 472 | i-04d089ed896cfafe1 Ready control-plane,master 4m53s v1.23.5 473 | i-072bf7de2e94e6f2d Ready 4m15s v1.23.5 474 | i-09b23242f40eabcca Ready control-plane,master 3m56s v1.23.5 475 | i-0cb1e2e7784768b22 Ready 3m57s v1.23.5 476 | 477 | root@i-04d089ed896cfafe1:~# kubectl get ns 478 | NAME STATUS AGE 479 | cert-manager Active 85s 480 | default Active 4m55s 481 | ingress-nginx Active 87s # <- ingress controller ns 482 | kube-flannel Active 4m32s 483 | kube-node-lease Active 4m55s 484 | kube-public Active 4m56s 485 | kube-system Active 4m56s 486 | 487 | root@i-04d089ed896cfafe1:~# kubectl get pods --all-namespaces 488 | NAMESPACE NAME READY STATUS RESTARTS AGE 489 | cert-manager cert-manager-66d9545484-h4d9h 1/1 Running 0 47s 490 | cert-manager cert-manager-cainjector-7d8b6bd6fb-zl7sg 1/1 Running 0 47s 491 | cert-manager cert-manager-webhook-669b96dcfd-b5pgk 1/1 Running 0 47s 492 | ingress-nginx ingress-nginx-admission-create-g62rk 0/1 Completed 0 50s 493 | ingress-nginx ingress-nginx-admission-patch-n9tc5 0/1 Completed 0 50s 494 | ingress-nginx ingress-nginx-controller-5c778bffff-bmk2c 1/1 Running 0 50s 495 | kube-flannel kube-flannel-ds-5fvx9 1/1 Running 0 3m45s 496 | kube-flannel kube-flannel-ds-bvqkc 1/1 Running 1 (3m13s ago) 3m35s 497 | kube-flannel kube-flannel-ds-hgxtn 1/1 Running 1 (111s ago) 2m40s 498 | kube-flannel kube-flannel-ds-kp6tl 1/1 Running 0 3m27s 499 | kube-flannel kube-flannel-ds-nvbbg 1/1 Running 0 3m55s 500 | kube-flannel kube-flannel-ds-rhsqq 1/1 Running 0 2m42s 501 | kube-system aws-node-termination-handler-478lj 1/1 Running 0 26s 502 | kube-system aws-node-termination-handler-5bk96 1/1 Running 0 26s 503 | kube-system aws-node-termination-handler-bkzrf 1/1 Running 0 26s 504 | kube-system aws-node-termination-handler-cx5ps 1/1 Running 0 26s 505 | kube-system aws-node-termination-handler-dfr44 1/1 Running 0 26s 506 | kube-system aws-node-termination-handler-vcq7z 1/1 Running 0 26s 507 | kube-system coredns-5d78c9869d-n7jcq 1/1 Running 0 4m1s 508 | kube-system coredns-5d78c9869d-w9k5j 1/1 Running 0 4m1s 509 | kube-system efs-csi-controller-74695cd876-66bw5 3/3 Running 0 28s 510 | kube-system efs-csi-controller-74695cd876-hl9g7 3/3 Running 0 28s 511 | kube-system efs-csi-node-7wgff 3/3 Running 0 27s 512 | kube-system efs-csi-node-9v4nv 3/3 Running 0 27s 513 | kube-system efs-csi-node-mjz2r 3/3 Running 0 27s 514 | kube-system efs-csi-node-n4npv 3/3 Running 0 27s 515 | kube-system efs-csi-node-pmpnc 3/3 Running 0 27s 516 | kube-system efs-csi-node-s4prq 3/3 Running 0 27s 517 | kube-system etcd-i-012c258d537d5ec2f 1/1 Running 0 4m4s 518 | kube-system etcd-i-018fb1214f9fe07fe 1/1 Running 0 3m7s 519 | kube-system etcd-i-0f73570d6dddb6d0b 1/1 Running 0 3m27s 520 | kube-system kube-apiserver-i-012c258d537d5ec2f 1/1 Running 0 4m6s 521 | kube-system kube-apiserver-i-018fb1214f9fe07fe 1/1 Running 1 (3m4s ago) 3m4s 522 | kube-system kube-apiserver-i-0f73570d6dddb6d0b 1/1 Running 0 3m26s 523 | kube-system kube-controller-manager-i-012c258d537d5ec2f 1/1 Running 1 (3m15s ago) 4m7s 524 | kube-system kube-controller-manager-i-018fb1214f9fe07fe 1/1 Running 0 2m9s 525 | kube-system kube-controller-manager-i-0f73570d6dddb6d0b 1/1 Running 0 3m26s 526 | kube-system kube-proxy-4lwgv 1/1 Running 0 2m40s 527 | kube-system kube-proxy-9hgtr 1/1 Running 0 3m27s 528 | kube-system kube-proxy-d6zzp 1/1 Running 0 4m1s 529 | kube-system kube-proxy-jwb8x 1/1 Running 0 3m35s 530 | kube-system kube-proxy-q2ctc 1/1 Running 0 2m42s 531 | kube-system kube-proxy-sgn7r 1/1 Running 0 3m45s 532 | kube-system kube-scheduler-i-012c258d537d5ec2f 1/1 Running 1 (3m12s ago) 4m6s 533 | kube-system kube-scheduler-i-018fb1214f9fe07fe 1/1 Running 0 3m1s 534 | kube-system kube-scheduler-i-0f73570d6dddb6d0b 1/1 Running 0 3m26s 535 | ``` 536 | 537 | #### Public LB check 538 | 539 | We can now test the public load balancer, nginx ingress controller and the security group ingress rules. On your local PC run: 540 | 541 | ``` 542 | curl -k -v https://k8s-ext-.elb.amazonaws.com/ 543 | * Trying 34.x.x.x:443... 544 | * TCP_NODELAY set 545 | * Connected to k8s-ext-.elb.amazonaws.com (34.x.x.x) port 443 (#0) 546 | * ALPN, offering h2 547 | * ALPN, offering http/1.1 548 | * successfully set certificate verify locations: 549 | * CAfile: /etc/ssl/certs/ca-certificates.crt 550 | CApath: /etc/ssl/certs 551 | * TLSv1.3 (OUT), TLS handshake, Client hello (1): 552 | * TLSv1.3 (IN), TLS handshake, Server hello (2): 553 | * TLSv1.2 (IN), TLS handshake, Certificate (11): 554 | * TLSv1.2 (IN), TLS handshake, Server key exchange (12): 555 | * TLSv1.2 (IN), TLS handshake, Server finished (14): 556 | * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): 557 | * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): 558 | * TLSv1.2 (OUT), TLS handshake, Finished (20): 559 | * TLSv1.2 (IN), TLS handshake, Finished (20): 560 | * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 561 | * ALPN, server accepted to use h2 562 | * Server certificate: 563 | * subject: C=IT; ST=Italy; L=Brescia; O=GL Ltd; OU=IT; CN=testlb.domainexample.com; emailAddress=email@you.com 564 | * start date: Apr 11 08:20:12 2022 GMT 565 | * expire date: Apr 11 08:20:12 2023 GMT 566 | * issuer: C=IT; ST=Italy; L=Brescia; O=GL Ltd; OU=IT; CN=testlb.domainexample.com; emailAddress=email@you.com 567 | * SSL certificate verify result: self signed certificate (18), continuing anyway. 568 | * Using HTTP2, server supports multi-use 569 | * Connection state changed (HTTP/2 confirmed) 570 | * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 571 | * Using Stream ID: 1 (easy handle 0x55c6560cde10) 572 | > GET / HTTP/2 573 | > Host: k8s-ext-.elb.amazonaws.com 574 | > user-agent: curl/7.68.0 575 | > accept: */* 576 | > 577 | * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! 578 | < HTTP/2 404 579 | < date: Tue, 12 Apr 2022 10:08:18 GMT 580 | < content-type: text/html 581 | < content-length: 146 582 | < strict-transport-security: max-age=15724800; includeSubDomains 583 | < 584 | 585 | 404 Not Found 586 | 587 |

404 Not Found

588 |
nginx
589 | 590 | 591 | * Connection #0 to host k8s-ext-.elb.amazonaws.com left intact 592 | ``` 593 | 594 | *404* is a correct response since the cluster is empty. 595 | 596 | ## Deploy a sample stack 597 | 598 | [Deploy ECK](deployments/) on Kubernetes 599 | 600 | ## Clean up 601 | 602 | ``` 603 | terraform destroy 604 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------