This guide goes through building functions to container images and then deploying them in a separate process.
If you followed the function-deployment guide, you built and deployed a function in a single convenient step using the nuctl CLI. However, it is sometimes desirable to build a function once and deploy it many times with different configuration. This guide will walk you through that process using nuctl.
In this scenario, you'll use the Go hello-world example.
function.yaml:
apiVersion: "nuclio.io/v1beta1"
kind: "NuclioFunction"
spec:
description: Showcases unstructured logging and a structured response.
runtime: "golang"
minReplicas: 1
maxReplicas: 1
handler: main:Handler
helloworld.go:
package main
import (
"github.com/nuclio/nuclio-sdk-go"
)
func Handler(context *nuclio.Context, event nuclio.Event) (interface{}, error) {
context.Logger.Info("This is an unstructured %s", "log")
return nuclio.Response{
StatusCode: 200,
ContentType: "application/text",
Body: []byte("Hello, from Nuclio :]"),
}, nil
}Using nuctl, you can issue a build - specifying the URL of the Go hello-world:
nuctl build hello-world --path https://raw.githubusercontent.com/nuclio/nuclio/master/hack/examples/golang/helloworld/helloworld.go \
--registry $(minikube ip):5000This produces the nuclio/processor-hello-world:latest image and pushes it to 192.168.64.8:5000. The image contains everything the function needs to run, except a configuration file.
To deploy the function to your platform, you'll use the nuctl deploy command with the --run-image option. When --run-image is present, nuctl does not initiate a build process - only creates a function in the platform and waits for it to become ready.
nuctl deploy hello-world --run-image localhost:5000/nuclio/processor-hello-world:latest \
--runtime golang \
--handler main:Handler \
--namespace nuclioYou can deploy this function several times, providing different labels, triggers, etc. - yet still use the same image.