Skip to content

Commit a7d59e1

Browse files
authored
Merge pull request #269 from 100-hours-a-week/feat/v3-k8s-iac
fix: Ansible SSM 배포 안정성 수정
2 parents eb7e7bc + 009a6cc commit a7d59e1

8 files changed

Lines changed: 48 additions & 5 deletions

File tree

IaC/3-v3/ansible/ansible.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ roles_path = ./roles
33
inventory = ./inventory/aws_ec2.yaml
44
host_key_checking = False
55
timeout = 60
6-
7-
[ssh_connection]
8-
pipelining = True
6+
deprecation_warnings = False

IaC/3-v3/ansible/inventory/aws_ec2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ compose:
2929
ansible_host: instance_id
3030
ansible_connection: "'aws_ssm'"
3131
ansible_aws_ssm_region: "'ap-northeast-2'"
32+
ansible_aws_ssm_bucket_name: "'dojangkok-v3-ansible-ssm'"
3233
ansible_user: ubuntu
3334
k8s_role: tags['k8s:role']
3435
k8s_nodepool: tags['k8s:nodepool']

IaC/3-v3/ansible/playbooks/site.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
- name: Install cluster components
3131
hosts: role_control_plane
3232
become: true
33+
environment:
34+
KUBECONFIG: /home/ubuntu/.kube/config
3335
roles:
3436
- calico
3537
- ebs-csi

IaC/3-v3/ansible/roles/calico/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
spec:
2424
calicoNetwork:
2525
ipPools:
26-
- cidr: {{ pod_cidr }}
26+
- cidr: "{{ pod_cidr }}"
2727
encapsulation: VXLAN
2828
natOutgoing: Enabled
2929
mtu: {{ calico_vxlan_mtu }}

IaC/3-v3/ansible/roles/kubeadm-init/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
set_fact:
4545
kubeadm_join_command: "{{ join_command.stdout }}"
4646

47+
- name: Install Helm
48+
shell: |
49+
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
50+
args:
51+
creates: /usr/local/bin/helm
52+
4753
- name: Label CP node
4854
command: >
4955
kubectl label node {{ inventory_hostname }}

IaC/3-v3/ansible/roles/kubeadm-join/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
register: kubelet_conf
1010

1111
- name: Join cluster
12-
command: "{{ hostvars[groups['role_control_plane'][0]].kubeadm_join_command }}"
12+
command: "{{ hostvars[groups['role_control_plane'][0]].kubeadm_join_command }} --node-name={{ inventory_hostname }}"
1313
when: not kubelet_conf.stat.exists
1414

1515
- name: Label worker node (from CP)

IaC/3-v3/aws/modules/iam/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,28 @@ resource "aws_iam_role_policy_attachment" "ssm" {
8383
role = aws_iam_role.k8s_node.name
8484
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
8585
}
86+
87+
# --- S3 for Ansible SSM file transfer ---
88+
89+
resource "aws_iam_role_policy" "ssm_s3" {
90+
name = "ssm-s3-transfer"
91+
role = aws_iam_role.k8s_node.id
92+
93+
policy = jsonencode({
94+
Version = "2012-10-17"
95+
Statement = [{
96+
Effect = "Allow"
97+
Action = [
98+
"s3:GetObject",
99+
"s3:PutObject",
100+
"s3:DeleteObject",
101+
"s3:GetBucketLocation",
102+
"s3:ListBucket"
103+
]
104+
Resource = [
105+
"arn:aws:s3:::dojangkok-v3-ansible-ssm",
106+
"arn:aws:s3:::dojangkok-v3-ansible-ssm/*"
107+
]
108+
}]
109+
})
110+
}

IaC/3-v3/aws/modules/k8s-nodes/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resource "aws_instance" "control_plane" {
3535
vpc_security_group_ids = var.cp_security_group_ids
3636
iam_instance_profile = var.iam_instance_profile
3737
source_dest_check = false
38+
user_data = local.ssm_user_data
3839

3940
metadata_options {
4041
http_endpoint = "enabled"
@@ -63,6 +64,15 @@ resource "aws_instance" "control_plane" {
6364
# --- Worker Nodes ---
6465

6566
locals {
67+
ssm_user_data = <<-EOF
68+
#!/bin/bash
69+
mkdir -p /tmp/ssm && cd /tmp/ssm
70+
curl -fsSL "https://s3.amazonaws.com/ec2-downloads-ssm/latest/debian_arm64/amazon-ssm-agent.deb" -o amazon-ssm-agent.deb
71+
dpkg -i amazon-ssm-agent.deb
72+
systemctl enable amazon-ssm-agent
73+
systemctl start amazon-ssm-agent
74+
EOF
75+
6676
# workers_per_az × 3 AZ → 플랫 맵 생성
6777
# e.g. workers_per_az=1 → { "w-2a-1"={az="a",...}, "w-2b-1"={...}, "w-2c-1"={...} }
6878
# e.g. workers_per_az=2 → { "w-2a-1"={...}, "w-2a-2"={...}, "w-2b-1"={...}, ... }
@@ -87,6 +97,7 @@ resource "aws_instance" "workers" {
8797
vpc_security_group_ids = var.worker_security_group_ids
8898
iam_instance_profile = var.iam_instance_profile
8999
source_dest_check = false
100+
user_data = local.ssm_user_data
90101

91102
metadata_options {
92103
http_endpoint = "enabled"

0 commit comments

Comments
 (0)