blob: 58372d9cf24e46f200d84fe9b7b326ba73ffff90 [file] [log] [blame]
garciadeblas0bc87522021-10-20 22:16:17 +02001#!/usr/bin/env bash
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set +eux
16
17# MicroK8s installation
18sudo snap install yq
19sudo snap install microk8s --classic
20sudo usermod -a -G microk8s ubuntu
21newgrp microk8s
22sudo microk8s.status --wait-ready
23sudo microk8s.enable storage dns
24# sudo microk8s.enable storage rbac
25# sudo microk8s.enable storage helm
26# sudo microk8s.enable storage helm3
27
28# Enables MetalLB
29PRIVATE_IP=$(hostname -I | awk '{print $1}')
30echo ${PRIVATE_IP}
31sudo microk8s.enable metallb:${PRIVATE_IP}-${PRIVATE_IP}
32
33# Updates the certificate to allow connections from outside as well (i.e. to the "public" IP).
34#sudo microk8s.stop
35sudo sed -i "s/\#MOREIPS/IP.3 = ${NEW_K8S_IP}/g" /var/snap/microk8s/current/certs/csr.conf.template
36cat /var/snap/microk8s/current/certs/csr.conf.template
37#sudo microk8s.refresh-certs -i
38#sudo microk8s.start
39
40# Retrieves and saves the credentials
41sudo microk8s.config | sed "s/server: .*/server: https:\/\/${NEW_K8S_IP}:16443/g" \
42| tee ${HOME}/.kube/config
43echo
44echo Credentials saved at ${HOME}/.kube/config
45echo
46
47return 0
48