-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitialize.sh
executable file
·58 lines (45 loc) · 1.42 KB
/
initialize.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
#!/bin/bash
. ~/.bashrc
PROJECT="$1"
ZONE="$2"
CLUSTER="$3"
KEYFILE="$4"
if [ -z "$KEYFILE" ];then
echo "Usage: $(basename "$0") PROJECT ZONE CLUSTER KEYFILE"
echo
echo "Arguments:"
echo " PROJECT The project ID in which the cluster resides"
echo " ZONE Availability zone to use"
echo " CLUSTER The GCE container cluster to be managed"
echo " KEYFILE Service account json key file to use"
exit 1
fi
if [ ! -f "$KEYFILE" ];then
echo "No such file: $KEYFILE"
exit 2
fi
if [ -d secrets/.kube ];then
echo "Already initialized, directory secrets/.kube exists"
exit 0
fi
EMAIL=$(grep -E client_email "$KEYFILE"| cut -d\" -f 4)
gcloud auth activate-service-account "$EMAIL" --key-file "$KEYFILE"
gcloud container clusters get-credentials "$CLUSTER" --zone="$ZONE" --project="$PROJECT"
gcloud config set project "$PROJECT"
echo -e '\nTesting use of the kubectl command'
if ! kubectl version; then
echo "Error: failed to interact with cluster"
exit 3
fi
mv .config .kube secrets/
ln -s secrets/.config
ln -s secrets/.kube
cat <<EOS
Success! kubectl and gcloud commands initialized
Usage:
docker run --rm -ti -v \$PWD/secrets/.config:/root/.config -v \$PWD/secrets/.kube:/root/.kube tomologic/kubeadmin <command> <args>'
Examples:
alias c="docker run --rm -ti -v \$PWD/secrets/.config:/root/.config -v \$PWD/secrets/.kube:/root/.kube tomologic/kubeadmin"
c kubectl get pods
c gcloud container clusters list
EOS