You need to have Docker installed on your machine, arkade is also recommended for installing the necessary tools, however you can install them manually if you prefer.
#!/bin/shset-oerrexit
# 1. Create registry container unless it already existsreg_name='kind-registry'reg_port='5001'if["$(dockerinspect-f'{{.State.Running}}'"${reg_name}"2>/dev/null||true)"!='true'];thendockerrun\-d--restart=always-p"127.0.0.1:${reg_port}:5000"--networkbridge--name"${reg_name}"\registry:2
fi# 2. Create kind cluster with containerd registry config dir enabled# TODO: kind will eventually enable this by default and this patch will# be unnecessary.## See:# https://github.com/kubernetes-sigs/kind/issues/2875# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
cat<<EOF | kind create cluster --config=-kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4containerdConfigPatches:- |- [plugins."io.containerd.grpc.v1.cri".registry] config_path = "/etc/containerd/certs.d"EOF# 3. Add the registry config to the nodes## This is necessary because localhost resolves to loopback addresses that are# network-namespace local.# In other words: localhost in the container is not localhost on the host.## We want a consistent name that works from both ends, so we tell containerd to# alias localhost:${reg_port} to the registry container when pulling imagesREGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"fornodein$(kindgetnodes);dodockerexec"${node}"mkdir-p"${REGISTRY_DIR}"cat<<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"[host."http://${reg_name}:5000"]EOFdone# 4. Connect the registry to the cluster network if not already connected# This allows kind to bootstrap the network but ensures they're on the same networkif["$(dockerinspect-f='{{json .NetworkSettings.Networks.kind}}'"${reg_name}")"='null'];thendockernetworkconnect"kind""${reg_name}"fi# 5. Document the local registry# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat<<EOF | kubectl apply -f -apiVersion: v1kind: ConfigMapmetadata: name: local-registry-hosting namespace: kube-publicdata: localRegistryHosting.v1: | host: "localhost:${reg_port}" help: "https://kind.sigs.k8s.io/docs/user/local-registry/"EOF
We will take an example of a simple function; a dictionary that returns the meaning of word you query. We will be using the PyDictionary module for this setup.
With our setup ready; we can now build our image, push it to the registry, and deploy it to Kubernetes. And using faas-cli it is possible with a single command!
We can invoke our function from CLI using faas-cli or curl.
$echo"advocate"|faas-cliinvokepydict
{"Noun":["a person who pleads for a cause or propounds an idea","a lawyer who pleads cases in court"],"Verb":["push for something","speak, plead, or argue in favor of"]}