Last active
December 27, 2022 19:50
-
-
Save kcotten/c0009773c0b3f60ae6a248113bba3062 to your computer and use it in GitHub Desktop.
k8s Setup Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/bash | |
# Setup new server with microk8s, kubectl, and helm | |
set -euo pipefail | |
# Get current user | |
USER=$(who | awk '{ print $1}') | |
# Get current OS, script currently uses snap which should be available | |
# by default on Ubuntu | |
OS=$(awk -F= '/^NAME/{print $2}' /etc/os-release | xargs) | |
# Check if microk8s is installed | |
INSTALLED=$(which microk8s) | |
if [[ -n "$INSTALLED" ]]; then | |
echo "Microk8s already installed..." | |
exit | |
fi | |
if [[ "$OS" != "Ubuntu" ]]; then | |
echo "Unsupported OS..." | |
exit | |
fi | |
# install kubectl and microk8 | |
sudo snap install kubectl --classic | |
sudo snap install microk8s --classic | |
# add user to config | |
sudo usermod -a -G microk8s $USER | |
sudo chown -f -R $USER ~/.kube | |
# restart group | |
newgrp microk8s | |
# output | |
microk8s status --wait-ready | |
# copy config for system kubectl | |
microk8s config > ~/.kube/config | |
chmod go-r ~/.kube/config | |
# Setup helm | |
sudo snap install helm --classic | |
# alias | |
echo "alias k='kubectl'" >> ~/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment