-
Notifications
You must be signed in to change notification settings - Fork 4
/
set-kubeconfig.sh
26 lines (19 loc) · 1.08 KB
/
set-kubeconfig.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
#!/bin/bash
source config.sh
export PRIVATE_KEY="$PWD/keys/key.pem"
eval $(ssh-agent -s)
ssh-add $PRIVATE_KEY
PORTAL_DEPLOYMENTS_ROOT=deployments
PUBLIC_IP=`awk -F'@' '{ print $2 }' $PORTAL_DEPLOYMENTS_ROOT'/'$PORTAL_DEPLOYMENT_REFERENCE/group_vars/no-floating.yml | sed s/\"\'//`
HOSTNAME=`ansible -b --become-user=root -i $PORTAL_DEPLOYMENTS_ROOT'/'$PORTAL_DEPLOYMENT_REFERENCE'/hosts' kube-master[0] -m setup -a 'filter=ansible_hostname' | grep ansible_hostname | awk -F':' '{ print $2}' | sed s/\"//g | sed -e 's/^[[:space:]]*//'`
sed -i 's+https://.*:6443+https://'"$HOSTNAME"':6443+' artifacts/admin.conf
echo "Add this line to your external /etc/hosts if needed:"
echo "$PUBLIC_IP $HOSTNAME"
echo "$PUBLIC_IP $HOSTNAME" >> /etc/hosts
echo "$PUBLIC_IP $HOSTNAME" >> artifacts/to-add-to-your-etc-hosts
echo "Execute the following line in this shell to connect to your cluster through kubectl:"
echo "export KUBECONFIG=artifacts/admin.conf"
echo ""
echo "To connect through ssh:"
echo "ssh -i keys/key.pem ubuntu@$PUBLIC_IP"
echo "ssh -i keys/key.pem ubuntu@$PUBLIC_IP" >> artifacts/ssh-connect