Skip to content

Instantly share code, notes, and snippets.

@LucasRoesler
Forked from burtonr/of-kind.sh
Created February 17, 2019 18:22
Show Gist options
  • Save LucasRoesler/c5f673c4a8aa3bab8f82b8a9b287ae28 to your computer and use it in GitHub Desktop.
Save LucasRoesler/c5f673c4a8aa3bab8f82b8a9b287ae28 to your computer and use it in GitHub Desktop.
OpenFaaS on KinD quickstart
#!/bin/bash
echo "> Be KinD with OpenFaaS"
# First, check if docker is available
docker version | 2>/dev/null
if [ $? -ne 0 ]; then
echo "> Docker is required for running OpenFaaS on KinD"
echo "> Install with: 'curl -sLS https://get.docker.com | sudo sh'"
exit 1
fi
# Make sure kubectl is available
kubectl version | 2>/dev/null
if [ $? -ne 0 ]; then
echo "> kubectl is required for running KinD"
echo "> Install on macOS: 'brew install kubernetes-cli' most Linux: 'sudo snap install kubectl --classic'"
exit 1
fi
# Make sure go is available
go version | 2>/dev/null
if [ $? -ne 0 ]; then
echo "> Go is required for running KinD"
echo "> Follow this link to download and install GoLang: https://golang.org/dl/"
exit 1
fi
# Make sure helm is available
helm version | 2>/dev/null
if [ $? -ne 0 ]; then
echo "> Helm is recommended for running OpenFaaS on Kubernetes"
echo "> Install with: 'curl -sLSf https://raw.githubusercontent.com/helm/helm/master/scripts/get | sudo bash'"
exit 1
fi
# Make sure faas-cli is available
faas-cli version | 2>/dev/null
if [ $? -ne 0 ]; then
echo "> faas-cli is recommended for working with OpenFaaS"
echo "> Install on macOS: 'brew install faas-cli' or with: 'curl -sLSf https://cli.openfaas.com | sudo sh'"
exit 1
fi
echo "> 'go get'-ing KinD"
go get sigs.k8s.io/kind
echo "> creating new KinD cluster 'openfaas'"
kind create cluster --name openfaas
echo "> switching kubectl context to KinD cluster"
export KUBECONFIG="$(kind get kubeconfig-path --name="openfaas")"
echo "> creating Tiller ServiceAccount"
kubectl -n kube-system create sa tiller \
&& kubectl create clusterrolebinding tiller \
--clusterrole cluster-admin \
--serviceaccount=kube-system:tiller
echo "> installing Tiller server component to the KinD cluster"
helm init --skip-refresh --upgrade --service-account tiller
echo "> creating OpenFaaS namespaces"
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
# TODO: there should be a better way to know that tiller is ready to go...
echo "> sleeping for 30 seconds to give Tiller time to start"
sleep 30s
echo "> installing OpenFaaS via helm"
helm repo add openfaas https://openfaas.github.io/faas-netes && \
helm repo update && \
helm upgrade openfaas --install openfaas/openfaas \
--namespace openfaas \
--set basic_auth=false \
--set functionNamespace=openfaas-fn \
--set operator.create=true
echo "> verifying OpenFaaS is available"
kubectl --namespace=openfaas get deployments -l "release=openfaas, app=openfaas"
echo "> run the following command is OpenFaaS is not yet available"
echo "> kubectl --namespace=openfaas get deployments -l \"release=openfaas, app=openfaas\""
echo
echo
echo "> Final steps:"
echo "> * forward the OpenFaaS gateway port to access the UI: 'kubectl port-forward svc/gateway -n openfaas 8080:8080'"
echo "> * Deploy a sample function from the store: 'faas-cli store deploy figlet'"
echo "> * Test the function: 'echo Hi! | faas-cli invoke figlet'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment