Local Docker registry in K3d and OpenFaas

405 views Asked by At

I am tinkering around with OpenFaas and K3D in order to build a serverless infrastructure for local development. For this to work efficiently I wanted to add a docker registry locally with K3D and have OpenFaas pull images from there, however I am confused about how I can use the host machine's IP as a registry source.

In order to create the cluster I used the following commands

  k3d cluster create garden --registry-create
  k3d kubeconfig merge garden --kubeconfig-switch-context 

  # Create local-path-provisioner
  kustomize build "github.com/rancher/local-path-provisioner/deploy?ref=master" | kubectl apply -f -

  # Install OpenFaaS
  arkade install openfaas
  kubectl rollout status -n openfaas deploy/gateway

  ## Forward local 8080 port
  kubectl port-forward -n openfaas svc/gateway 8080:8080 & 

  PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)
  echo -n $PASSWORD | faas-cli login --username admin --password-stdin

  kubectl get secret basic-auth -n openfaas -o yaml > basic-auth.yml
  vim basic-auth.yml # change namespace to `openfaas-fn`
  kubectl apply -f basic-auth.yml 

So building a sample function works fine, but obviously OpenFaas/Kubernetes will not be able to reach the docker registry

version: 1.0
provider:
  name: openfaas
  gateway: http://127.0.0.1:8080
functions:
  main:
    lang: node12
    handler: ./main
    image: 127.0.0.1:5000/main:latest

The only solution I have in mind is to configure a DNS service within K3d that can resolve to the hosts' Docker registry.

Does anyone have an idea how this could be done easier?

Fortunately I do not need this for production systems as they would pull images from an external registry.

0

There are 0 answers