Knative CLI
Knative CLI Red Hat OpenShift Serverless 1.35 Overview of CLI commands for Knative Functions, Serving, and Eventing Red Hat OpenShift Documentation Team
kn service create <service-name> --image <image> --tag <tag-value> kn service create showcase --image quay.io/openshift-knative/showcase Creating service 'showcase' in namespace 'default': 0.271s The Route is still working to reflect the latest desired specification. 0.580s Configuration "showcase" is waiting for a Revision to become ready. 3.857s 3.861s Ingress has not yet been reconciled. 4.270s Ready to serve. Service 'showcase' created with latest revision 'showcase-00001' and URL: http://showcase-default.apps-crc.testing kn service update <service_name> --env <key>=<value> kn service update <service_name> --port 80 kn service update <service_name> --request cpu=500m --limit memory=1024Mi --limit cpu=1000m kn service update <service_name> --tag <revision_name>=latest kn service update <service_name> --untag testing --tag @latest=staging kn service update <service_name> --tag <revision_name>=test --traffic test=10,@latest=90 kn service apply <service_name> --image <image> kn service apply <service_name> --image <image> --env <key>=<value> kn service apply <service_name> -f <filename> kn service describe --verbose <service_name> Name: showcase Namespace: default Age: 2m URL: http://showcase-default.apps.ocp.example.com Revisions: 100% @latest (showcase-00001) [1] (2m) Image: quay.io/openshift-knative/showcase (pinned to aaea76) Conditions: OK TYPE AGE REASON ++ Ready 1m ++ ConfigurationsReady 1m ++ RoutesReady 1m Name: showcase Namespace: default Annotations: serving.knative.dev/creator=system:admin serving.knative.dev/lastModifier=system:admin Age: 3m URL: http://showcase-default.apps.ocp.example.com Cluster: http://showcase.default.svc.cluster.local Revisions: 100% @latest (showcase-00001) [1] (3m) Image: quay.io/openshift-knative/showcase (pinned to aaea76) Env: GREET=Bonjour Conditions: OK TYPE AGE REASON ++ Ready 3m ++ ConfigurationsReady 3m ++ RoutesReady 3m kn service describe <service_name> -o yaml kn service describe <service_name> -o json kn service describe <service_name> -o url kn service create showcase --image quay.io/openshift-knative/showcase --target ./ --namespace test Service 'showcase' created in namespace 'test'. tree ./ ./ └── test └── ksvc └── showcase.yaml 2 directories, 1 file cat test/ksvc/showcase.yaml apiVersion: serving.knative.dev/v1 kind: Service metadata: creationTimestamp: null name: showcase namespace: test spec: template: metadata: annotations: client.knative.dev/user-image: quay.io/openshift-knative/showcase creationTimestamp: null spec: containers: - image: quay.io/openshift-knative/showcase name: "" resources: {} status: {} kn service describe showcase --target ./ --namespace test Name: showcase Namespace: test Age: URL: Revisions: Conditions: OK TYPE AGE REASON kn service create -f test/ksvc/showcase.yaml Creating service 'showcase' in namespace 'test': 0.058s The Route is still working to reflect the latest desired specification. 0.098s 0.168s Configuration "showcase" is waiting for a Revision to become ready. 23.377s 23.419s Ingress has not yet been reconciled. 23.534s Waiting for load balancer to be ready 23.723s Ready to serve. Service 'showcase' created to latest revision 'showcase-00001' is available at URL: http://showcase-test.apps.example.com kn container add <container_name> --image <image_uri> kn container add sidecar --image docker.io/example/sidecar containers: - image: docker.io/example/sidecar name: sidecar resources: {} kn container add <first_container_name> --image <image_uri> | kn container add <second_container_name> --image <image_uri> | kn service create <service_name> --image <image_uri> --extra-containers - kn container add sidecar --image docker.io/example/sidecar:first | kn container add second --image docker.io/example/sidecar:second | kn service create my-service --image docker.io/example/my-app:latest --extra-containers - kn service create <service_name> --image <image_uri> --extra-containers <filename> kn service create my-service --image docker.io/example/my-app:latest --extra-containers my-extra-containers.yaml kn domain create <domain_mapping_name> --ref <target_name> kn domain create example.com --ref showcase kn domain create <domain_mapping_name> --ref <ksvc:service_name:service_namespace> kn domain create example.com --ref ksvc:showcase:example-namespace kn domain create <domain_mapping_name> --ref <kroute:route_name> kn domain create example.com --ref kroute:example-route kn domain list -n <domain_mapping_namespace> kn domain describe <domain_mapping_name> kn domain update --ref <target> kn domain delete <domain_mapping_name> plugins: path-lookup: true 1 directory: ~/.config/kn/plugins 2 eventing: sink-mappings: 3 - prefix: svc 4 group: core 5 version: v1 6 resource: services 7 kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format> kn event build -o yaml data: {} datacontenttype: application/json id: 81a402a2-9c29-4c27-b8ed-246a253c9e58 source: kn-event/v0.4.0 specversion: "1.0" time: "2021-10-15T10:42:57.713226203Z" type: dev.knative.cli.plugin.event.generic kn event build --field operation.type=local-wire-transfer --field operation.amount=2345.40 --field operation.from=87656231 --field operation.to=2344121 --field automated=true --field signature='FGzCPLvYWdEgsdpb3qXkaVp7Da0=' --type org.example.bank.bar --id USD(head -c 10 < /dev/urandom | base64 -w 0) --output json { "specversion": "1.0", "id": "RjtL8UH66X+UJg==", "source": "kn-event/v0.4.0", "type": "org.example.bank.bar", "datacontenttype": "application/json", "time": "2021-10-15T10:43:23.113187943Z", "data": { "automated": true, "operation": { "amount": "2345.40", "from": 87656231, "to": 2344121, "type": "local-wire-transfer" }, "signature": "FGzCPLvYWdEgsdpb3qXkaVp7Da0=" } } kn event send --field <field-name>=<value> --type <type-name> --id <id> --to-url <url> --to <cluster-resource> --namespace <namespace> kn event send --field player.id=6354aa60-ddb1-452e-8c13-24893667de20 --field player.game=2345 --field points=456 --type org.example.gaming.foo --to-url http://ce-api.foo.example.com/ kn event send --type org.example.kn.ping --id USD(uuidgen) --field event.type=test --field event.data=98765 --to Service:serving.knative.dev/v1:event-display kn source list-types TYPE NAME DESCRIPTION ApiServerSource apiserversources.sources.knative.dev Watch and send Kubernetes API events to a sink PingSource pingsources.sources.knative.dev Periodically send ping events to a sink SinkBinding sinkbindings.sources.knative.dev Binding for connecting a PodSpecable to a sink kn source list-types -o yaml kn source binding create bind-heartbeat --namespace sinkbinding-example --subject "Job:batch/v1:app=heartbeat-cron" --sink http://event-display.svc.cluster.local \ 1 --ce-override "sink=bound" kn source container create <container_source_name> --image <image_uri> --sink <sink> kn source container delete <container_source_name> kn source container describe <container_source_name> kn source container list kn source container list -o yaml kn source container update <container_source_name> --image <image_uri> apiVersion: v1 kind: ServiceAccount metadata: name: events-sa namespace: default 1 --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: event-watcher namespace: default 2 rules: - apiGroups: - "" resources: - events verbs: - get - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: k8s-ra-event-watcher namespace: default 3 roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: event-watcher subjects: - kind: ServiceAccount name: events-sa namespace: default 4 oc apply -f <filename> kn source apiserver create <event_source_name> --sink broker:<broker_name> --resource "event:v1" --service-account <service_account_name> --mode Resource kn service create event-display --image quay.io/openshift-knative/showcase kn trigger create <trigger_name> --sink ksvc:event-display oc create deployment event-origin --image quay.io/openshift-knative/showcase kn source apiserver describe <source_name> Name: mysource Namespace: default Annotations: sources.knative.dev/creator=developer, sources.knative.dev/lastModifier=developer Age: 3m ServiceAccountName: events-sa Mode: Resource Sink: Name: default Namespace: default Kind: Broker (eventing.knative.dev/v1) Resources: Kind: event (v1) Controller: false Conditions: OK TYPE AGE REASON ++ Ready 3m ++ Deployed 3m ++ SinkProvided 3m ++ SufficientPermissions 3m ++ EventTypesProvided 3m kn service describe event-display -o url oc logs USD(oc get pod -o name | grep event-display) -c user-container ☁\ufe0f cloudevents.Event Validation: valid Context Attributes, specversion: 1.0 type: dev.knative.apiserver.resource.update datacontenttype: application/json Data, { "apiVersion": "v1", "involvedObject": { "apiVersion": "v1", "fieldPath": "spec.containers{event-origin}", "kind": "Pod", "name": "event-origin", "namespace": "default", .. }, "kind": "Event", "message": "Started container", "metadata": { "name": "event-origin.159d7608e3a3572c", "namespace": "default", . }, "reason": "Started", } kn trigger delete <trigger_name> kn source apiserver delete <source_name> oc delete -f authentication.yaml kn service create event-display --image quay.io/openshift-knative/showcase kn source ping create test-ping-source --schedule "*/2 * * * *" --data '{"message": "Hello world!"}' --sink ksvc:event-display kn source ping describe test-ping-source Name: test-ping-source Namespace: default Annotations: sources.knative.dev/creator=developer, sources.knative.dev/lastModifier=developer Age: 15s Schedule: */2 * * * * Data: {"message": "Hello world!"} Sink: Name: event-display Namespace: default Resource: Service (serving.knative.dev/v1) Conditions: OK TYPE AGE REASON ++ Ready 8s ++ Deployed 8s ++ SinkProvided 15s ++ ValidSchedule 15s ++ EventTypeProvided 15s ++ ResourcesCorrect 15s watch oc get pods oc logs USD(oc get pod -o name | grep event-display) -c user-container ☁\ufe0f cloudevents.Event Validation: valid Context Attributes, specversion: 1.0 type: dev.knative.sources.ping source: /apis/v1/namespaces/default/pingsources/test-ping-source id: 99e4f4f6-08ff-4bff-acf1-47f61ded68c9 time: 2020-04-07T16:16:00.000601161Z datacontenttype: application/json Data, { "message": "Hello world!" } kn delete pingsources.sources.knative.dev <ping_source_name> kn service create event-display --image quay.io/openshift-knative/showcase kn source kafka create <kafka_source_name> --servers <cluster_kafka_bootstrap>.kafka.svc:9092 --topics <topic_name> --consumergroup my-consumer-group --sink event-display kn source kafka describe <kafka_source_name> Name: example-kafka-source Namespace: kafka Age: 1h BootstrapServers: example-cluster-kafka-bootstrap.kafka.svc:9092 Topics: example-topic ConsumerGroup: example-consumer-group Sink: Name: event-display Namespace: default Resource: Service (serving.knative.dev/v1) Conditions: OK TYPE AGE REASON ++ Ready 1h ++ Deployed 1h ++ SinkProvided 1h oc -n kafka run kafka-producer -ti --image=quay.io/strimzi/kafka:latest-kafka-2.7.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list <cluster_kafka_bootstrap>:9092 --topic my-topic oc logs USD(oc get pod -o name | grep event-display) -c user-container ☁\ufe0f cloudevents.Event Validation: valid Context Attributes, specversion: 1.0 type: dev.knative.kafka.event source: /apis/v1/namespaces/default/kafkasources/example-kafka-source#example-topic subject: partition:46#0 id: partition:46/offset:0 time: 2021-03-10T11:21:49.4Z Extensions, traceparent: 00-161ff3815727d8755848ec01c866d1cd-7ff3916c44334678-00 Data, Hello! kn func create -r <repository> -l <runtime> -t <template> <path> kn func create -l typescript -t cloudevents examplefunc Created typescript function in /home/user/demo/examplefunc kn func create -r https://github.com/boson-project/templates/ -l node -t hello-world examplefunc Created node function in /home/user/demo/examplefunc kn func run kn func run --path=<directory_path> kn func run --build kn func run --build=false kn func help run kn func build kn func build Building function image Function image has been built, image: registry.redhat.io/example/example-function:latest kn func build --registry quay.io/username Building function image Function image has been built, image: quay.io/username/example-function:latest kn func build --push kn func help build kn func deploy [-n <namespace> -p <path> -i <image>] Function deployed at: http://func.example.com kn func list [-n <namespace> -p <path>] NAME NAMESPACE RUNTIME URL READY example-function default node http://example-function.default.apps.ci-ln-g9f36hb-d5d6b.origin-ci-int-aws.dev.rhcloud.com True kn service list -n <namespace> NAME URL LATEST AGE CONDITIONS READY REASON example-function http://example-function.default.apps.ci-ln-g9f36hb-d5d6b.origin-ci-int-aws.dev.rhcloud.com example-function-gzl4c 16m 3 OK / 3 True kn func info [-f <format> -n <namespace> -p <path>] kn func info -p function/example-function Function name: example-function Function is built in image: docker.io/user/example-function:latest Function is deployed as Knative Service: example-function Function is deployed in namespace: default Routes: http://example-function.default.apps.ci-ln-g9f36hb-d5d6b.origin-ci-int-aws.dev.rhcloud.com kn func invoke kn func invoke --type <event_type> --source <event_source> --data <event_data> --content-type <content_type> --id <event_ID> --format <format> --namespace <namespace> kn func invoke --type ping --source example-ping --data "Hello world!" --content-type "text/plain" --id example-ID --format http --namespace my-ns kn func invoke --file <path> --content-type <content-type> kn func invoke --file ./test.json --content-type application/json kn func invoke --path <path_to_function> kn func invoke --path ./example/example-function kn func invoke kn func invoke --target <target> kn func invoke --target remote kn func invoke --target "https://my-event-broker.example.com" kn func invoke --target local kn func delete [<function_name> -n <namespace> -p <path>]