Skip to content

Commit def83b6

Browse files
committed
fix
1 parent c253624 commit def83b6

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

terraform/modules/k8s-cluster/main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ resource "aws_instance" "bastion" {
2626

2727
resource "null_resource" "copy-pem" {
2828
provisioner "local-exec" {
29-
command = "echo '${tls_private_key.node-key.private_key_openssh}' > ./node-key.pem"
29+
command = <<EOT
30+
echo '${tls_private_key.node-key.private_key_openssh}' > ./node-key.pem
31+
chmod 600 ./node-key.pem
32+
EOT
3033
}
3134

3235
# Now use the file provisioner to upload the private key to the bastion host
@@ -114,7 +117,7 @@ resource "null_resource" "setup-master" {
114117
]
115118
}
116119

117-
depends_on = [ aws_instance.master ]
120+
depends_on = [ null_resource.copy-pem ]
118121
}
119122

120123
resource "aws_instance" "worker" {

terraform/modules/k8s-cluster/master.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ echo "-------------Disabling swap-------------"
1010
swapoff -a
1111
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
1212

13+
# Install Dependencies
14+
echo "-------------Installing Required Packages-------------"
15+
apt-get update -y
16+
apt-get install -y curl wget gpg apt-transport-https ca-certificates
17+
1318
# Install Containerd
1419
echo "-------------Installing Containerd-------------"
1520
wget https://github.com/containerd/containerd/releases/download/v1.7.4/containerd-1.7.4-linux-amd64.tar.gz
@@ -66,14 +71,13 @@ sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables ne
6671
modprobe br_netfilter
6772
sysctl -p /etc/sysctl.conf
6873

69-
# Install kubectl, kubelet and kubeadm
70-
echo "-------------Installing Kubectl, Kubelet and Kubeadm-------------"
71-
apt-get update && sudo apt-get install -y apt-transport-https curl
72-
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
73-
74-
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
75-
deb https://apt.kubernetes.io/ kubernetes-xenial main
76-
EOF
74+
# Check if the key file already exists
75+
if [ ! -f /etc/apt/keyrings/kubernetes-apt-keyring.gpg ]; then
76+
# Download the key if it doesn't exist
77+
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
78+
# Add the Kubernetes repository to the sources list
79+
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
80+
fi
7781

7882
apt update -y
7983
apt install -y kubelet kubeadm kubectl

0 commit comments

Comments
 (0)