Skip to content

Instantly share code, notes, and snippets.

@kcotten
Last active December 27, 2022 19:50
Show Gist options
  • Save kcotten/c0009773c0b3f60ae6a248113bba3062 to your computer and use it in GitHub Desktop.
Save kcotten/c0009773c0b3f60ae6a248113bba3062 to your computer and use it in GitHub Desktop.
k8s Setup Script
#! /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