Technology Stack:
- Knative
- Node.js
Simple Express service that returns a phonetic "Hello World" greeting for a configured country code. The app loads configuration from environment variables (via dotenv for local development) and supports deployment to Knative.
- Run the application
npm install
npm run dev- Set the greeting by updating
.envor exporting variables before running:
export COUNTRY_CODE=GA
export PORT=3000
npm startSelect the option that is most appropriate:
# Replace <registry>/<repo> with your container registry path
IMAGE=<REGISTRY>/<REPOSITORY>/hello-country-service:latest
podman build -t "$IMAGE" .
# or: docker build -t "$IMAGE" .
podman push "$IMAGE"
# or: docker push "$IMAGE"oc project <NAMESPACE>
REGISTRY=$(oc registry info)
podman login -u "$(oc whoami)" -p "$(oc whoami -t)" "$REGISTRY"
IMAGE=${REGISTRY}/<NAMESPACE>/hello-country-service:latest
podman build -t "$IMAGE" .
podman push "$IMAGE"# Point to the project that should own the image
oc project <NAMESPACE>
# Create a Docker strategy BuildConfig (run once)
oc new-build --strategy=docker --binary --name hello-country-service
# Start a build using the local working tree and stream logs
oc start-build hello-country-service --from-dir=. --follow
# Verify the resulting image stream tag
oc get is hello-country-service -n <NAMESPACE>The successful build publishes the image at:
image-registry.openshift-image-registry.svc:5000/<NAMESPACE>/hello-country-service:latest
- Update
knative-service.yamlwith your image reference (for OpenShift local registry, setyour-namespaceaccordingly), then apply it:
oc apply -f knative-service.yaml -n <NAMESPACE>- Knative injects a
PORTenvironment variable automatically; do not set one in the manifest. Override the greeting viaCOUNTRY_CODE.
Or, using the Knative CLI without modifying the YAML:
IMAGE=image-registry.openshift-image-registry.svc:5000/<NAMESPACE>/hello-country-service:latest
kn service apply hello-country-service \
--image "$IMAGE" \
--env COUNTRY_CODE=EN- Retrieve the URL:
kn service describe hello-country-service -o url- Test the service once it is ready:
curl "$(kn service describe hello-country-service -o url)"- To update the greeting later, patch the service:
kn service update hello-country-service --env COUNTRY_CODE=FR