-
Notifications
You must be signed in to change notification settings - Fork 4
/
ocp4-install.sh
executable file
·149 lines (125 loc) · 4.16 KB
/
ocp4-install.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
set -x
## Env
DIR=$(pwd)
INSTALL="0"
CLUSTER_NAME=${1}
REGION=${2}
BASE_DOMAIN=${3}
REPLICAS_CP=${4}
REPLICAS_WORKER=${5}
VPC=${6}
AWS_ID=${7}
AWS_SECRET_KEY=${8}
INSTANCE_TYPE=${9}
USERS=${10}
## Prerequisites
echo "This script install the latest stable version available for OCP..."
echo "Downloading OCP 4 installer if not exists:"
if [ ! -f ./ocp4-installer.tar.gz ]; then
wget -O ./ocp4-installer.tar.gz https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-install-linux.tar.gz && tar xvzf ./ocp4-installer.tar.gz
else
echo "Installer exists, using ./ocp4-installer.tar.gz. Unpacking..." ; echo " "
tar xvzf ./ocp4-installer.tar.gz
fi
if [ ! -f ./install/install-dir-$CLUSTER_NAME/terraform.cluster.tfstate ]; then
echo "AWS credentials: "; echo " "
aws configure set region $REGION
cat << EOF > ~/.aws/credentials
[default]
aws_access_key_id = $AWS_ID
aws_secret_access_key = $AWS_SECRET_KEY
EOF
cleanup() {
rm -f ./openshift-install
rm -f .ssh-keys/myocp*
}
echo "Generating SSH key pair" ; echo " "
mkdir -p .ssh-keys
rm -f .ssh-keys/myocp_$CLUSTER_NAME ; ssh-keygen -t rsa -b 4096 -N '' -f .ssh-keys/myocp_$CLUSTER_NAME
eval "$(ssh-agent -s)"
ssh-add .ssh-keys/myocp_$CLUSTER_NAME
ssh-add -L
## Install config file
echo "Creating install config file" ; echo " "
rm -f ./install/install-dir-$CLUSTER_NAME/install-config.yaml && rm -f ./install/install-dir-$CLUSTER_NAME/.openshift_install* ; #./openshift-install create install-config --dir=install-dir-$CLUSTER_NAME
mkdir -p backup && mkdir ./backup/backup-$CLUSTER_NAME/
mkdir -p install && mkdir ./install/install-dir-$CLUSTER_NAME/
PULL_SECRET=$(cat ./pullsecret.txt)
SSH_KEY=$(cat .ssh-keys/myocp_$CLUSTER_NAME.pub)
if [ $VPC != false ]; then
echo "Existing VPC is $VPC..."
SUBNET_IDS=$(aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPC --query 'Subnets[?MapPublicIpOnLaunch==`false`].SubnetId' --output text)
var=$'subnets:\n'
for instance in $SUBNET_IDS; do envInstances+=(${instance}); done
for i in ${envInstances[@]};
do
var+=" "-" "\'$i\'$'\n'
done
EXISTING_VPC=$var
echo "Existing subnets are $EXISTING_VPC"
else
EXISTING_VPC=""
echo "No existing VPC..."
fi
cat << EOF > ./backup/backup-$CLUSTER_NAME/install-config.yaml
apiVersion: v1
baseDomain: $BASE_DOMAIN
compute:
- architecture: amd64
hyperthreading: Enabled
name: worker
platform: #{}
aws:
type: $INSTANCE_TYPE #m6i.4xlarge
replicas: $REPLICAS_WORKER
controlPlane:
architecture: amd64
hyperthreading: Enabled
name: master
platform: #{}
aws:
type: $INSTANCE_TYPE #m6i.4xlarge
replicas: $REPLICAS_CP
metadata:
creationTimestamp: null
name: $CLUSTER_NAME
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
machineNetwork:
- cidr: 10.0.0.0/16
networkType: OVNKubernetes
serviceNetwork:
- 172.30.0.0/16
platform:
aws:
region: $REGION
$EXISTING_VPC
pullSecret: '$PULL_SECRET'
sshKey: $SSH_KEY
EOF
cp ./backup/backup-$CLUSTER_NAME/install-config.yaml ./install/install-dir-$CLUSTER_NAME/install-config.yaml
cat ./install/install-dir-$CLUSTER_NAME/install-config.yaml
echo "Edit the installation file ./install/install-dir-$CLUSTER_NAME/install-config.yaml if you need."
echo "Confirm when you are ready:" ; echo " "
while true; do
read -p "Proceed with OCP cluster installation: yY|nN -> " yn
case $yn in
[Yy]* ) echo "Installing OCP4 cluster... " ; INSTALL="1" ; break;;
[Nn]* ) echo "Aborting installation..." ; cleanup ; ssh-add -D ; exit;;
* ) echo "Select yes or no";;
esac
done
if [ $INSTALL -gt 0 ]; then
./openshift-install create cluster --dir=install/install-dir-$CLUSTER_NAME --log-level=info
echo "Set HTPasswd as Identity Provider" ; echo " "
./oauth.sh $CLUSTER_NAME $VPC $USERS
ssh-add -D
fi
else
echo "An OCP cluster exists. Skipping installation..."
echo "Remove the install-dir folder and run the script."
fi
exit