Skip to content

Commit

Permalink
added dev box support (#22)
Browse files Browse the repository at this point in the history
* added dev box support
* added v 11 disclaimer
  • Loading branch information
bartr authored Oct 21, 2022
1 parent 6a8fa55 commit d6630a7
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 46 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Pilot-in-a-Box Overview

## Breaking Changes in 0.11.0

- Version 0.11.0 has breaking changes from 0.10.0
- The CLIs will automatically use the latest when you create a new Codespace
- Using the 0.11.0 or higher CLIs on an 0.10.0 branch will break
- To check the version of your CLI
- `kic -v`
- `flt -v`
- If you have an existing branch with work you want to save and create a new Codespace you can downgrade the CLI in that CS
- Make sure you're in the root of your branch repo
- `.devcontainer/cli-update.sh 0.10.0`
- To go back to the current CLI
- `.devcontainer/cli-update.sh`

## Introduction

Kubernetes is hard. Getting started and set up for the first time can take weeks to get right. Managing deployments on a fleet of Kubernetes clusters on the edge brings even more challenges.

Pilot-in-a-Box (PiB) is a `game-changer` for the end-to-end Kubernetes app development cycle from a local cluster to deployments on the edge. It reduces the initial friction and empowers the developer to get started and deployed to a dev/test environment within *minutes*. The pre-configured Codespaces environment includes a `Kubernetes` cluster and custom CLI's (`kic` and `flt`) that help streamline the initial learning curve to Kubernetes development commands.
Expand Down
Binary file added docs/images/PiB-Deploy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vm/scripts/arc-token
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/zsh

if [ "$PIB_ARC_ENABLED" != "true" ]; then
echo "cluster is not Arc enabled"
Expand Down
2 changes: 1 addition & 1 deletion vm/scripts/check-flux
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh

hdrsort()
{
Expand Down
2 changes: 1 addition & 1 deletion vm/scripts/check-heartbeat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh

if [ "$PIB_SSL" = "" ]; then
res=$(curl -s http://localhost/heartbeat/17)
Expand Down
2 changes: 1 addition & 1 deletion vm/scripts/check-logs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh

#shellcheck disable=2028
echo "\ncloud-init log\n$(sudo tail /var/log/cloud-init-output.log)\n\nstatus log\n$(tail status)"
2 changes: 1 addition & 1 deletion vm/scripts/check-setup
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/bin/zsh

tail -n1 status
2 changes: 1 addition & 1 deletion vm/scripts/curl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ "$1" == "" ]
if [ "$1" = "" ]
then
echo "Error: /path is required"
echo "usage: flt curl /path"
Expand Down
2 changes: 1 addition & 1 deletion vm/scripts/patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh
echo "$(date +'%Y-%m-%d %H:%M:%S') patched" >> /home/pib/status

docker pull ghcr.io/cse-labs/pib-webv:latest
Expand Down
4 changes: 2 additions & 2 deletions vm/scripts/pull
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/bin/zsh
# pull the latest git updates
git -C "$HOME/gitops" pull
git -C "$HOME/pib" pull
2 changes: 1 addition & 1 deletion vm/scripts/sync
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh

# run flux reconcile
flux reconcile source git gitops
26 changes: 21 additions & 5 deletions vm/scripts/update-cli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh

tag=$1

Expand All @@ -7,15 +7,31 @@ mkdir -p "$HOME/bin"
cd "$HOME/bin" || exit

# remove old CLI
rm -rf kic .kic
rm -rf kic .kic flt .flt

if [ "$tag" = "" ]; then
# use latest release
tag=$(curl -s https://api.github.com/repos/kubernetes101/pib-dev/releases/latest | grep tag_name | cut -d '"' -f4)
fi

wget -O kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/kic-$tag-linux-amd64.tar.gz"
tar -xvzf kic.tar.gz
rm kic.tar.gz
if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
# install kic
wget -O kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/kic-$tag-linux-amd64.tar.gz"
tar -xvzf kic.tar.gz
rm kic.tar.gz

# install flt
wget -O flt.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/flt-$tag-linux-amd64.tar.gz"
tar -xvzf flt.tar.gz
rm flt.tar.gz

flt completion zsh > "$HOME/.oh-my-zsh/completions/_flt"
else
wget -O kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/kic-$tag-linux-amd64.tar.gz"
tar -xvzf kic.tar.gz
rm kic.tar.gz
fi

kic completion zsh > "$HOME/.oh-my-zsh/completions/_kic"

cd "$OLDPWD" || exit
2 changes: 1 addition & 1 deletion vm/setup/arc-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

# change to this directory
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
Expand Down
13 changes: 9 additions & 4 deletions vm/setup/flux-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

echo "$(date +'%Y-%m-%d %H:%M:%S') flux bootstrap start" >> "$HOME/status"

# inner-loop
if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
exit 0
fi

# setup Arc enabled flux
if [ "$PIB_ARC_ENABLED" = "true" ]
then
Expand Down Expand Up @@ -45,15 +50,15 @@ fi

git pull

kubectl apply -f "$HOME/gitops/clusters/$PIB_CLUSTER/flux-system/namespace.yaml"
kubectl apply -f "$HOME/pib/clusters/$PIB_CLUSTER/flux-system/namespace.yaml"
flux create secret git flux-system -n flux-system --url "$PIB_FULL_REPO" -u gitops -p "$PIB_PAT"
flux create secret git gitops -n flux-system --url "$PIB_FULL_REPO" -u gitops -p "$PIB_PAT"

kubectl apply -f "$HOME/gitops/clusters/$PIB_CLUSTER/flux-system/controllers.yaml"
kubectl apply -f "$HOME/pib/clusters/$PIB_CLUSTER/flux-system/controllers.yaml"
sleep 3
kubectl apply -f "$HOME/gitops/clusters/$PIB_CLUSTER/flux-system/source.yaml"
kubectl apply -f "$HOME/pib/clusters/$PIB_CLUSTER/flux-system/source.yaml"
sleep 2
kubectl apply -R -f "$HOME/gitops/clusters/$PIB_CLUSTER/flux-system"
kubectl apply -R -f "$HOME/pib/clusters/$PIB_CLUSTER/flux-system"
sleep 5

# force flux to sync
Expand Down
81 changes: 67 additions & 14 deletions vm/setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,50 @@ echo "installing cli"

mkdir -p "$HOME/bin"

cd "$HOME" || exit

# set zsh as default shell
sudo sed -i "s|/bin/bash|/bin/zsh|g" /etc/passwd

# install oh-my-zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
git clone https://github.com/ohmyzsh/oh-my-zsh .oh-my-zsh
cp ".oh-my-zsh/templates/zshrc.zsh-template" .zshrc

{
echo ""
echo "compinit"
} >> ".zshrc"
fi

# use latest release
tag=$(curl -s https://api.github.com/repos/kubernetes101/pib-dev/releases/latest | grep tag_name | cut -d '"' -f4)

cd "$HOME/bin" || exit
wget -O vm-kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/vm-kic-$tag-linux-amd64.tar.gz"
tar -xvzf vm-kic.tar.gz
rm vm-kic.tar.gz

if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
# install kic
wget -O kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/kic-$tag-linux-amd64.tar.gz"
tar -xvzf kic.tar.gz
rm kic.tar.gz

# install flt
wget -O flt.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/flt-$tag-linux-amd64.tar.gz"
tar -xvzf flt.tar.gz
rm flt.tar.gz
else
wget -O vm-kic.tar.gz "https://github.com/kubernetes101/pib-dev/releases/download/$tag/vm-kic-$tag-linux-amd64.tar.gz"
tar -xvzf vm-kic.tar.gz
rm vm-kic.tar.gz
fi

cd "$OLDPWD" || exit

echo "$(date +'%Y-%m-%d %H:%M:%S') installing libs" >> "$HOME/status"
sudo apt-get install -y net-tools software-properties-common libssl-dev libffi-dev python-dev build-essential lsb-release gnupg-agent

echo "$(date +'%Y-%m-%d %H:%M:%S') installing utils" >> "$HOME/status"
sudo apt-get install -y curl git wget nano jq zip unzip httpie
sudo apt-get install -y zsh curl git wget nano jq zip unzip httpie
sudo apt-get install -y dnsutils coreutils gnupg2 make bash-completion gettext iputils-ping

# add Docker source
Expand All @@ -39,6 +69,9 @@ echo "$(date +'%Y-%m-%d %H:%M:%S') adding kubernetes source" >> "$HOME/status"
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

# set shell to zsh
sudo sed -i "s|/bin/bash|/bin/zsh|g" /etc/passwd

echo "$(date +'%Y-%m-%d %H:%M:%S') updating sources" >> "$HOME/status"

# this is failing on large fleets - add one retry
Expand Down Expand Up @@ -73,26 +106,46 @@ wget "https://github.com/derailed/k9s/releases/download/${VERSION}/k9s_Linux_x86
sudo tar -zxvf k9s_Linux_x86_64.tar.gz -C /usr/local/bin
rm -f k9s_Linux_x86_64.tar.gz

# update pib.bashrc
mkdir -p "$HOME/.oh-my-zsh/completions"
flux completion zsh > "$HOME/.oh-my-zsh/completions/_flux"
k3d completion zsh > "$HOME/.oh-my-zsh/completions/_k3d"
kubectl completion zsh > "$HOME/.oh-my-zsh/completions/_kubectl"

"$HOME/bin/kic" completion zsh > "$HOME/.oh-my-zsh/completions/_kic"

if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
"$HOME/bin/flt" completion zsh > "$HOME/.oh-my-zsh/completions/_flt"
fi

# update .zshenv
{
echo "export PATH=\$PATH:\$HOME/bin"
echo ""
echo "shopt -s expand_aliases"
echo "export PATH=\$PATH:\$HOME/bin"
echo ""
echo "alias k='kubectl'"
echo "alias kaf='kubectl apply -f'"
echo "alias kak='kubectl apply -k'"
echo "alias kdelf='kubectl delete -f'"
echo "alias kj='kubectl exec -it jumpbox -- bash -l'"
echo "alias kje='kubectl exec -it jumpbox -- '"
echo ""
echo "source <(flux completion bash)"
echo "source <(k3d completion bash)"
echo "source <(kic completion bash)"
echo "source <(kubectl completion bash)"
} >> "$HOME/.zshenv"

{
echo ""
echo "shopt -s expand_aliases"
echo ""
echo 'complete -F __start_kubectl k'
} >> "$HOME/pib.bashrc"
echo "source \$HOME/.zshenv"
} > "$HOME/.bashrc"

# configure git CLI
git config --global user.name pib-gitops
git config --global user.email pib-gitops@outlook.com
git config --global core.whitespace blank-at-eol,blank-at-eof,space-before-tab
git config --global pull.rebase false
git config --global init.defaultbranch main
git config --global fetch.prune true
git config --global core.pager more
git config --global credential.helper store

# upgrade Ubuntu
echo "$(date +'%Y-%m-%d %H:%M:%S') upgrading" >> "$HOME/status"
Expand Down
8 changes: 8 additions & 0 deletions vm/setup/k8s-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ cd "$(dirname "${BASH_SOURCE[0]}")" || exit

echo "$(date +'%Y-%m-%d %H:%M:%S') k3d-setup start" >> "$HOME/status"

if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
"$HOME/bin/kic" cluster create

echo "$(date +'%Y-%m-%d %H:%M:%S') k3d-setup complete" >> "$HOME/status"

exit 0
fi

# fail if k3d.yaml isn't present
if [ ! -f ./k3d.yaml ]
then
Expand Down
8 changes: 3 additions & 5 deletions vm/setup/post-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ echo "$(date +'%Y-%m-%d %H:%M:%S') post start" >> "$HOME/status"
docker pull ghcr.io/cse-labs/pib-webv:latest
docker pull ghcr.io/cse-labs/pib-webv:beta

kubectl run jumpbox --image=ghcr.io/cse-labs/jumpbox --restart=Always

cli/kivm sync

kubectl get pods -A
if [ "$PIB_IS_INNER_LOOP" != "true" ]; then
kubectl run jumpbox --image=ghcr.io/cse-labs/jumpbox --restart=Always
fi

echo "$(date +'%Y-%m-%d %H:%M:%S') post complete" >> "$HOME/status"
4 changes: 4 additions & 0 deletions vm/setup/pre-flux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# this runs before flux-setup.sh

if [ "$PIB_IS_INNER_LOOP" = "true" ]; then
exit 0
fi

echo "$(date +'%Y-%m-%d %H:%M:%S') pre-flux start" >> "$HOME/status"

# change to this directory
Expand Down
14 changes: 8 additions & 6 deletions vm/setup/pre-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

echo "$(date +'%Y-%m-%d %H:%M:%S') pre-k3d start" >> "$HOME/status"

echo "$(date +'%Y-%m-%d %H:%M:%S') creating registry" >> "$HOME/status"
# create local registry
docker network create k3d
if ! docker network ls | grep k3d; then
echo "$(date +'%Y-%m-%d %H:%M:%S') creating registry" >> "$HOME/status"
# create local registry
docker network create k3d

# create container registry
k3d registry create registry.localhost --port 5500
docker network connect k3d k3d-registry.localhost
# create container registry
k3d registry create registry.localhost --port 5500
docker network connect k3d k3d-registry.localhost
fi

# add the host name to /etc/hosts
{
Expand Down
2 changes: 1 addition & 1 deletion vm/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### to run manually
# cd $HOME
# gitops/vm/setup/setup.sh
# pib/vm/setup/setup.sh

# this is the main VM setup script

Expand Down

0 comments on commit d6630a7

Please sign in to comment.