Git Product home page Git Product logo

Comments (7)

alexellis avatar alexellis commented on September 24, 2024 1

Hi @brianjenkins94

I haven't seen anything in your issue that makes it seem like OpenFaaS or K8s wouldn't work in a devcontainer specifically. I think a better title for this issue would be: "How do I use a local registry with OpenFaaS?"

There are some instructions that were contributed based upon a KinD (not an OpenFaaS) guide on how to use a registry on the same machine - https://docs.openfaas.com/tutorials/local-kind-registry/

Setting up a registry on localhost is a bit advanced, perhaps you'd prefer to use a short-lived registry instead like ttl.sh?

We use it a lot for local development and testing.

I'll get this closed, and let us know how you get on with ttl.sh or the KinD project's instructions for local registries.

Alex

from faas.

alexellis avatar alexellis commented on September 24, 2024 1

Delete everything that you have and only run the commands from the tutorial. The port is 5001 and you need to use localhost not the IP.

from faas.

alexellis avatar alexellis commented on September 24, 2024 1

No problem.

If you'd like to help support the time we spend maintaining OpenFaaS and supporting users via GitHub, please consider setting up a GitHub Sponsorship with a set or custom tier. We want the Community Edition to continue to be available for free users 🙂

https://github.com/sponsors/openfaas/

from faas.

brianjenkins94 avatar brianjenkins94 commented on September 24, 2024

Okay, I am now reasonably certain that the problems I am encountering are because I haven't set up a self-signed certificate.

It still seems weird to me that I was able to push the image to the registry without issue, but retrieving it is the problem.

For those following along at home, we are here:

devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/typescript-node
{
	"name": "Existing Dockerfile",
	"build": {
		"context": "../docker/",
		"dockerfile": "../docker/Dockerfile"
	},
	"remoteUser": "root",
	"customizations": {
		"vscode": {
			"extensions": [
				"dbaeumer.vscode-eslint",
				"ms-vscode-remote.remote-containers",
				"streetsidesoftware.code-spell-checker",
				"unifiedjs.vscode-mdx"
			]
		}
	},
	"features": {
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
			"version": "latest",
			"moby": true
		},
		"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
			"minikube": "none",
			"version": "latest"
		}
	},
	"forwardPorts": [8080],
	"postCreateCommand": "/entrypoint.sh",
	"runArgs": ["--network=host"]
}
Dockerfile
# syntax=docker/dockerfile:1.4

FROM mcr.microsoft.com/devcontainers/base:ubuntu

ENV container=docker

ENV OPENFAAS_URL=http://localhost:8080

RUN sudo apt-get update > /dev/null \
	# Node.js
	&& wget -qO- https://deb.nodesource.com/setup_lts.x | sudo sh \
	# Common
	&& sudo apt-get install -y file nodejs \
	# Arkade
	&& curl -fsSL https://get.arkade.dev | sudo sh

COPY --chmod=755 ./entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/sh

# kind
arkade get kind
sudo mv ~/.arkade/bin/kind /usr/local/bin/

kind delete cluster

docker container rm --force "$(docker ps --filter name="kind-" --all --quiet)"

docker run -d --restart=always -p 127.0.0.1:5000:5000 --name "kind-registry" registry:2

sed "s/\t/  /g" <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
	[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
		endpoint = ["http://kind-registry:5000"]
nodes:
- role: control-plane
	extraPortMappings:
	- containerPort: 31112
		hostPort: 8080
EOF

if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "kind-registry")" = 'null' ]; then
	docker network connect "kind" "kind-registry"
fi

sed "s/\t/  /g" <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
	name: local-registry-hosting
	namespace: kube-public
data:
	localRegistryHosting.v1: |
		host: "localhost:5000"
		help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

# OpenFaaS
arkade install openfaas
kubectl rollout status -n openfaas deploy

# faas-cli
arkade get faas-cli
sudo mv ~/.arkade/bin/faas-cli /usr/local/bin/

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

npm install

npm run faas

echo "> Listening on http://admin:$PASSWORD@localhost:8080/"

There's something wrong with the volume mount currently. It's getting mounted as an empty folder.

from faas.

alexellis avatar alexellis commented on September 24, 2024

I had absolutely no issues running KinD and OpenFaaS in a devcontainer, and by following the tutorial in the openfaas docs (referenced above), I was also able to use a local registry.

Screenshot 2023-05-12 at 21 08 49

Let me know if this helped 🙂

from faas.

brianjenkins94 avatar brianjenkins94 commented on September 24, 2024

Hey Alex, I hugely appreciate you taking a look.

You were able to get everything working just by following the KinD guide?

You didn't have to do anything extra with htaccess, certificates, or setting imagePullSecrets?

Weird that I've been running into so many issues. I'll start again from scratch and see if I can make sense of how I got here.

Thanks!

from faas.

brianjenkins94 avatar brianjenkins94 commented on September 24, 2024

It worked 🤦‍♂️

I've updated my previous comment to reflect what worked in the end.

Basically I thought myself smarter than the tutorial and thought I could expose the registry on the host and then get rid of what I had thought would be unnecessary redirection.

Rest assured I feel very silly now 🙂

from faas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.