-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.sh
63 lines (41 loc) · 2.06 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
d=`date +%F%H%M`
sudo adduser jenkins$d
#To get kubectl
sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/v"$1".0/bin/linux/amd64/kubectl
sudo chmod +x ./kubectl
sudo mkdir -p /home/jenkins$d/bin && sudo mv ./kubectl /home/jenkins$d/bin/kubectl && sudo chmod -R 755 /home/jenkins$d/ && export PATH=$PATH:/home/jenkins$d/bin
kubectl version --short --client
echo "Kubectl Installed"
wget https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.3.0/heptio-authenticator-aws_0.3.0_linux_amd64 -O heptio-authenticator-aws
sudo chmod +x heptio-authenticator-aws
sudo mv ./heptio-authenticator-aws /home/jenkins$d/bin/heptio-authenticator-aws && export PATH=$PATH:/home/jenkins$d/bin
sudo chown -R jenkins$d.jenkins$d /home/jenkins$d/bin/
heptio-authenticator-aws help
echo "aws-heptio-authenticator Installed"
if [ $2 == "dev" ]
then
echo "Dev"
sed -i 's|REPLACEME|arn:aws:iam::861112368680:role/worker-nodes-role|g' config-map-aws-auth.yaml
elif [ $2 == "pprod" ]
then
echo "Preprod"
sed -i 's|REPLACEME|arn:aws:iam::861112368680:role/worker-nodes-role2|g' config-map-aws-auth.yaml
else
echo "Prod"
sed -i 's|REPLACEME|arn:aws:iam::861112368680:role/worker-nodes-role3|g' config-map-aws-auth.yaml
fi
#Terraform output from kubeconfig
sudo mkdir -p /home/jenkins$d/.kube
sudo terraform output kubeconfig > config-1
sudo mv config-1 /home/jenkins$d/.kube/config && sudo chown -R jenkins$d.jenkins$d /home/jenkins$d/.kube/
#Deploying config-map for join worker nodes.
sudo mv config-map-aws-auth.yaml /home/jenkins$d/config-map-aws-auth.yaml
#sudo -H -u jenkins$d bash -c 'echo 'export PATH=$PATH:/home/jenkins$d/bin' >> /home/jenkins$d/.bashrc'
#sudo -H -u jenkins$d bash -c '/home/jenkins$d/bin/kubectl create -f /home/jenkins$d/config-map-aws-auth.yaml'
#sudo su -l -p jenkins$d config.sh
sudo -i -u jenkins$d bash << EOF
echo "export PATH=$PATH:/home/jenkins$d/bin" >> /home/jenkins$d/.bashrc
source /home/jenkins$d/.bashrc
/home/jenkins$d/bin/kubectl create -f /home/jenkins$d/config-map-aws-auth.yaml
EOF