Skip to content

Commit 67d2946

Browse files
readme now has instructions for basic kubectl operation testing. locals map used to aid in userdata
1 parent 9ed2780 commit 67d2946

File tree

9 files changed

+165
-86
lines changed

9 files changed

+165
-86
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
.kitchen.local.yml
88
Gemfile.lock
99
terraform.tfstate.d/
10-
config
10+
kubeconfig
1111
config-map-aws-auth.yaml

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
66
project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [v0.1.0] - 2018-06-06
8+
## [v0.1.0] - 2018-06-07
99

1010
### Added
1111

1212
- Everything! Initial release of the module.
13+
- Kudos to @tanmng for finding and fixing bug #1.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ This module has been packaged with [awspec](https://github.com/k1LoW/awspec) tes
4747
3. Ensure your AWS environment is configured (i.e. credentials and region) for test.
4848
4. Test using `bundle exec kitchen test` from the root of the repo.
4949

50+
For now, connectivity to the kubernetes cluster is not tested but will be in the future.
51+
To test your kubectl connection manually, see the [eks_test_fixture README](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_test_fixture/README.md).
52+
5053
## Doc generation
5154

5255
Documentation should be modified within `main.tf` and generated using [terraform-docs](https://github.com/segmentio/terraform-docs).

data.tf

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -29,84 +29,3 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" {
2929
}
3030
}
3131
}
32-
33-
resource "null_resource" "tags_as_list_of_maps" {
34-
count = "${length(keys(var.tags))}"
35-
36-
triggers = "${map(
37-
"key", "${element(keys(var.tags), count.index)}",
38-
"value", "${element(values(var.tags), count.index)}",
39-
"propagate_at_launch", "true"
40-
)}"
41-
}
42-
43-
locals {
44-
asg_tags = ["${null_resource.tags_as_list_of_maps.*.triggers}"]
45-
46-
# More information: https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-nodegroup.yaml
47-
workers_userdata = <<USERDATA
48-
#!/bin/bash -xe
49-
50-
CA_CERTIFICATE_DIRECTORY=/etc/kubernetes/pki
51-
CA_CERTIFICATE_FILE_PATH=$CA_CERTIFICATE_DIRECTORY/ca.crt
52-
mkdir -p $CA_CERTIFICATE_DIRECTORY
53-
echo "${aws_eks_cluster.this.certificate_authority.0.data}" | base64 -d > $CA_CERTIFICATE_FILE_PATH
54-
INTERNAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
55-
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.this.endpoint},g /var/lib/kubelet/kubeconfig
56-
sed -i s,CLUSTER_NAME,${var.cluster_name},g /var/lib/kubelet/kubeconfig
57-
sed -i s,REGION,${data.aws_region.current.name},g /etc/systemd/system/kubelet.service
58-
sed -i s,MAX_PODS,20,g /etc/systemd/system/kubelet.service
59-
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.this.endpoint},g /etc/systemd/system/kubelet.service
60-
sed -i s,INTERNAL_IP,$INTERNAL_IP,g /etc/systemd/system/kubelet.service
61-
DNS_CLUSTER_IP=10.100.0.10
62-
if [[ $INTERNAL_IP == 10.* ]] ; then DNS_CLUSTER_IP=172.20.0.10; fi
63-
sed -i s,DNS_CLUSTER_IP,$DNS_CLUSTER_IP,g /etc/systemd/system/kubelet.service
64-
sed -i s,CERTIFICATE_AUTHORITY_FILE,$CA_CERTIFICATE_FILE_PATH,g /var/lib/kubelet/kubeconfig
65-
sed -i s,CLIENT_CA_FILE,$CA_CERTIFICATE_FILE_PATH,g /etc/systemd/system/kubelet.service
66-
systemctl daemon-reload
67-
systemctl restart kubelet kube-proxy
68-
USERDATA
69-
70-
config_map_aws_auth = <<CONFIGMAPAWSAUTH
71-
apiVersion: v1
72-
kind: ConfigMap
73-
metadata:
74-
name: aws-auth
75-
namespace: kube-system
76-
data:
77-
mapRoles: |
78-
- rolearn: ${aws_iam_role.workers.arn}
79-
username: system:node:{{EC2PrivateDNSName}}
80-
groups:
81-
- system:bootstrappers
82-
- system:nodes
83-
CONFIGMAPAWSAUTH
84-
85-
kubeconfig = <<KUBECONFIG
86-
87-
apiVersion: v1
88-
clusters:
89-
- cluster:
90-
server: ${aws_eks_cluster.this.endpoint}
91-
certificate-authority-data: ${aws_eks_cluster.this.certificate_authority.0.data}
92-
name: kubernetes
93-
contexts:
94-
- context:
95-
cluster: kubernetes
96-
user: aws
97-
name: aws
98-
current-context: aws
99-
kind: Config
100-
preferences: {}
101-
users:
102-
- name: aws
103-
user:
104-
exec:
105-
apiVersion: client.authentication.k8s.io/v1alpha1
106-
command: heptio-authenticator-aws
107-
args:
108-
- "token"
109-
- "-i"
110-
- "${var.cluster_name}"
111-
KUBECONFIG
112-
}

examples/eks_test_fixture/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ This set of templates serves a few purposes. It:
66
2. serves as the test infrastructure for CI on the project.
77
3. provides a simple way to play with the Kubernetes cluster you create.
88

9+
## testing with kubectl
10+
11+
Once converged, `kubeconfig` and `config-map-aws-auth.yml` should be in this directory.
12+
Ensure you have a recent version of `kubectl` on your PATH ([instructions here](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl))
13+
14+
```bash
15+
curl -o heptio-authenticator-aws https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/darwin/amd64/heptio-authenticator-aws
16+
mv heptio-authenticator-aws ~/go/bin/
17+
kubectl apply -f examples/eks_test_fixture/config-map-aws-auth.yaml --kubeconfig examples/eks_test_fixture/kubeconfig
18+
# configmap "aws-auth" created
19+
kubectl get nodes --watch --kubeconfig examples/eks_test_fixture/kubeconfig
20+
```
21+
922
## IAM Permissions
1023

1124
The following IAM policy is the minimum needed to execute the module from the test suite.

examples/eks_test_fixture/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ resource "random_string" "suffix" {
4646
special = false
4747
}
4848

49-
resource "local_file" "config" {
49+
resource "local_file" "kubeconfig" {
5050
content = "${module.eks.kubeconfig}"
51-
filename = "${path.module}/config"
51+
filename = "${path.module}/kubeconfig"
5252
}
5353

5454
resource "local_file" "config-map-aws-auth" {
@@ -77,5 +77,5 @@ module "eks" {
7777
vpc_id = "${module.vpc.vpc_id}"
7878
workers_ami_id = "${data.aws_ami.eks_worker.id}"
7979
cluster_ingress_cidrs = ["${local.workstation_external_cidr}"]
80-
workers_instance_type = "t2.micro"
80+
workers_instance_type = "t2.small"
8181
}

local.tf

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
locals {
2+
# Mapping from the node type that we selected and the max number of pods that it can run
3+
# Taken from https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-nodegroup.yaml
4+
max_pod_per_node = {
5+
c4.large = 29
6+
c4.xlarge = 58
7+
c4.2xlarge = 58
8+
c4.4xlarge = 234
9+
c4.8xlarge = 234
10+
c5.large = 29
11+
c5.xlarge = 58
12+
c5.2xlarge = 58
13+
c5.4xlarge = 234
14+
c5.9xlarge = 234
15+
c5.18xlarge = 737
16+
i3.large = 29
17+
i3.xlarge = 58
18+
i3.2xlarge = 58
19+
i3.4xlarge = 234
20+
i3.8xlarge = 234
21+
i3.16xlarge = 737
22+
m3.medium = 12
23+
m3.large = 29
24+
m3.xlarge = 58
25+
m3.2xlarge = 118
26+
m4.large = 20
27+
m4.xlarge = 58
28+
m4.2xlarge = 58
29+
m4.4xlarge = 234
30+
m4.10xlarge = 234
31+
m5.large = 29
32+
m5.xlarge = 58
33+
m5.2xlarge = 58
34+
m5.4xlarge = 234
35+
m5.12xlarge = 234
36+
m5.24xlarge = 737
37+
p2.xlarge = 58
38+
p2.8xlarge = 234
39+
p2.16xlarge = 234
40+
p3.2xlarge = 58
41+
p3.8xlarge = 234
42+
p3.16xlarge = 234
43+
r3.xlarge = 58
44+
r3.2xlarge = 58
45+
r3.4xlarge = 234
46+
r3.8xlarge = 234
47+
r4.large = 29
48+
r4.xlarge = 58
49+
r4.2xlarge = 58
50+
r4.4xlarge = 234
51+
r4.8xlarge = 234
52+
r4.16xlarge = 737
53+
t2.small = 8
54+
t2.medium = 17
55+
t2.large = 35
56+
t2.xlarge = 44
57+
t2.2xlarge = 44
58+
x1.16xlarge = 234
59+
x1.32xlarge = 234
60+
}
61+
62+
asg_tags = ["${null_resource.tags_as_list_of_maps.*.triggers}"]
63+
64+
# More information: https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-nodegroup.yaml
65+
workers_userdata = <<USERDATA
66+
#!/bin/bash -xe
67+
68+
CA_CERTIFICATE_DIRECTORY=/etc/kubernetes/pki
69+
CA_CERTIFICATE_FILE_PATH=$CA_CERTIFICATE_DIRECTORY/ca.crt
70+
mkdir -p $CA_CERTIFICATE_DIRECTORY
71+
echo "${aws_eks_cluster.this.certificate_authority.0.data}" | base64 -d > $CA_CERTIFICATE_FILE_PATH
72+
INTERNAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
73+
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.this.endpoint},g /var/lib/kubelet/kubeconfig
74+
sed -i s,CLUSTER_NAME,${var.cluster_name},g /var/lib/kubelet/kubeconfig
75+
sed -i s,REGION,${data.aws_region.current.name},g /etc/systemd/system/kubelet.service
76+
sed -i s,MAX_PODS,${lookup(local.max_pod_per_node, var.workers_instance_type)},g /etc/systemd/system/kubelet.service
77+
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.this.endpoint},g /etc/systemd/system/kubelet.service
78+
sed -i s,INTERNAL_IP,$INTERNAL_IP,g /etc/systemd/system/kubelet.service
79+
DNS_CLUSTER_IP=10.100.0.10
80+
if [[ $INTERNAL_IP == 10.* ]] ; then DNS_CLUSTER_IP=172.20.0.10; fi
81+
sed -i s,DNS_CLUSTER_IP,$DNS_CLUSTER_IP,g /etc/systemd/system/kubelet.service
82+
sed -i s,CERTIFICATE_AUTHORITY_FILE,$CA_CERTIFICATE_FILE_PATH,g /var/lib/kubelet/kubeconfig
83+
sed -i s,CLIENT_CA_FILE,$CA_CERTIFICATE_FILE_PATH,g /etc/systemd/system/kubelet.service
84+
systemctl daemon-reload
85+
systemctl restart kubelet kube-proxy
86+
USERDATA
87+
88+
config_map_aws_auth = <<CONFIGMAPAWSAUTH
89+
apiVersion: v1
90+
kind: ConfigMap
91+
metadata:
92+
name: aws-auth
93+
namespace: kube-system
94+
data:
95+
mapRoles: |
96+
- rolearn: ${aws_iam_role.workers.arn}
97+
username: system:node:{{EC2PrivateDNSName}}
98+
groups:
99+
- system:bootstrappers
100+
- system:nodes
101+
CONFIGMAPAWSAUTH
102+
103+
kubeconfig = <<KUBECONFIG
104+
105+
apiVersion: v1
106+
clusters:
107+
- cluster:
108+
server: ${aws_eks_cluster.this.endpoint}
109+
certificate-authority-data: ${aws_eks_cluster.this.certificate_authority.0.data}
110+
name: kubernetes
111+
contexts:
112+
- context:
113+
cluster: kubernetes
114+
user: aws
115+
name: aws
116+
current-context: aws
117+
kind: Config
118+
preferences: {}
119+
users:
120+
- name: aws
121+
user:
122+
exec:
123+
apiVersion: client.authentication.k8s.io/v1alpha1
124+
command: heptio-authenticator-aws
125+
args:
126+
- "token"
127+
- "-i"
128+
- "${var.cluster_name}"
129+
KUBECONFIG
130+
}

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
* 3. Ensure your AWS environment is configured (i.e. credentials and region) for test.
4949
* 4. Test using `bundle exec kitchen test` from the root of the repo.
5050
51+
For now, connectivity to the kubernetes cluster is not tested but will be in the future.
52+
To test your kubectl connection manually, see the [eks_test_fixture README](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_test_fixture/README.md).
53+
5154
* ## Doc generation
5255
5356
* Documentation should be modified within `main.tf` and generated using [terraform-docs](https://github.com/segmentio/terraform-docs).

workers.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ resource "aws_iam_role_policy_attachment" "workers_AmazonEC2ContainerRegistryRea
9191
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
9292
role = "${aws_iam_role.workers.name}"
9393
}
94+
95+
resource "null_resource" "tags_as_list_of_maps" {
96+
count = "${length(keys(var.tags))}"
97+
98+
triggers = "${map(
99+
"key", "${element(keys(var.tags), count.index)}",
100+
"value", "${element(values(var.tags), count.index)}",
101+
"propagate_at_launch", "true"
102+
)}"
103+
}

0 commit comments

Comments
 (0)