|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// serverless/cli_reference/kn-offline-services.adoc |
| 4 | + |
| 5 | +[id="creating-an-offline-service_{context}"] |
| 6 | += Creating a service using offline mode |
| 7 | + |
| 8 | +.Prerequisites |
| 9 | + |
| 10 | +* {ServerlessOperatorName} and Knative Serving are installed on your cluster. |
| 11 | +* You have installed the `kn` CLI. |
| 12 | + |
| 13 | +.Procedure |
| 14 | + |
| 15 | +. In offline mode, create a local Knative service descriptor file: |
| 16 | ++ |
| 17 | +[source,terminal] |
| 18 | +---- |
| 19 | +$ kn service create event-display \ |
| 20 | + --image quay.io/openshift-knative/knative-eventing-sources-event-display:latest \ |
| 21 | + --target ./ \ |
| 22 | + --namespace test |
| 23 | +---- |
| 24 | ++ |
| 25 | +.Example output |
| 26 | +[source,terminal] |
| 27 | +---- |
| 28 | +Service 'event-display' created in namespace 'test'. |
| 29 | +---- |
| 30 | ++ |
| 31 | +* The `--target ./` flag enables offline mode and specifies `./` as the directory for storing the new directory tree. |
| 32 | ++ |
| 33 | +If you do not specify an existing directory, but use a filename, such as `--target my-service.yaml`, then no directory tree is created. Instead, only the service descriptor file `my-service.yaml` is created in the current directory. |
| 34 | ++ |
| 35 | +The filename can have the `.yaml`, `.yml`, or `.json` extension. Choosing `.json` creates the service descriptor file in the JSON format. |
| 36 | ++ |
| 37 | +* The `--namespace test` option places the new service in the `test` namespace. |
| 38 | ++ |
| 39 | +If you do not use `--namespace`, and you are logged in to an OpenShift cluster, the descriptor file is created in the current namespace. Otherwise, the descriptor file is created in the `default` namespace. |
| 40 | + |
| 41 | +. Examine the created directory structure: |
| 42 | ++ |
| 43 | +[source,terminal] |
| 44 | +---- |
| 45 | +$ tree ./ |
| 46 | +---- |
| 47 | ++ |
| 48 | +.Example output |
| 49 | +[source,terminal] |
| 50 | +---- |
| 51 | +./ |
| 52 | +└── test |
| 53 | + └── ksvc |
| 54 | + └── event-display.yaml |
| 55 | +
|
| 56 | +2 directories, 1 file |
| 57 | +---- |
| 58 | ++ |
| 59 | +* The current `./` directory specified with `--target` contains the new `test/` directory that is named after the specified namespace. |
| 60 | +* The `test/` directory contains the `ksvc` directory, named after the resource type. |
| 61 | +* The `ksvc` directory contains the descriptor file `event-display.yaml`, named according to the specified service name. |
| 62 | + |
| 63 | +. Examine the generated service descriptor file: |
| 64 | ++ |
| 65 | +[source,terminal] |
| 66 | +---- |
| 67 | +$ cat test/ksvc/event-display.yaml |
| 68 | +---- |
| 69 | ++ |
| 70 | +.Example output |
| 71 | +[source,yaml] |
| 72 | +---- |
| 73 | +apiVersion: serving.knative.dev/v1 |
| 74 | +kind: Service |
| 75 | +metadata: |
| 76 | + creationTimestamp: null |
| 77 | + name: event-display |
| 78 | + namespace: test |
| 79 | +spec: |
| 80 | + template: |
| 81 | + metadata: |
| 82 | + annotations: |
| 83 | + client.knative.dev/user-image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest |
| 84 | + creationTimestamp: null |
| 85 | + spec: |
| 86 | + containers: |
| 87 | + - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest |
| 88 | + name: "" |
| 89 | + resources: {} |
| 90 | +status: {} |
| 91 | +---- |
| 92 | + |
| 93 | +. List information about the new service: |
| 94 | ++ |
| 95 | +[source,terminal] |
| 96 | +---- |
| 97 | +$ kn service describe event-display --target ./ --namespace test |
| 98 | +---- |
| 99 | ++ |
| 100 | +.Example output |
| 101 | +[source,terminal] |
| 102 | +---- |
| 103 | +Name: event-display |
| 104 | +Namespace: test |
| 105 | +Age: |
| 106 | +URL: |
| 107 | +
|
| 108 | +Revisions: |
| 109 | +
|
| 110 | +Conditions: |
| 111 | + OK TYPE AGE REASON |
| 112 | +---- |
| 113 | + |
| 114 | +* The `--target ./` option specifies the root directory for the directory structure containing namespace subdirectories. |
| 115 | ++ |
| 116 | +Alternatively, you can directly specify a YAML or JSON filename with the `--target` option. The accepted file extensions are `.yaml`, `.yml`, and `.json`. |
| 117 | ++ |
| 118 | +* The `--namespace` option specifies the namespace, which communicates to `kn` the subdirectory that contains the necessary service descriptor file. |
| 119 | ++ |
| 120 | +If you do not use `--namespace`, and you are logged in to an OpenShift cluster, `kn` searches for the service in the subdirectory that is named after the current namespace. Otherwise, `kn` searches in the `default/` subdirectory. |
| 121 | + |
| 122 | +. Use the service descriptor file to create the service on the cluster: |
| 123 | ++ |
| 124 | +[source,terminal] |
| 125 | +---- |
| 126 | +$ kn service create -f test/ksvc/event-display.yaml |
| 127 | +---- |
| 128 | ++ |
| 129 | +.Example output |
| 130 | +[source,terminal] |
| 131 | +---- |
| 132 | +Creating service 'event-display' in namespace 'test': |
| 133 | +
|
| 134 | + 0.058s The Route is still working to reflect the latest desired specification. |
| 135 | + 0.098s ... |
| 136 | + 0.168s Configuration "event-display" is waiting for a Revision to become ready. |
| 137 | + 23.377s ... |
| 138 | + 23.419s Ingress has not yet been reconciled. |
| 139 | + 23.534s Waiting for load balancer to be ready |
| 140 | + 23.723s Ready to serve. |
| 141 | +
|
| 142 | +Service 'event-display' created to latest revision 'event-display-00001' is available at URL: |
| 143 | +http://event-display-test.apps.example.com |
| 144 | +---- |
0 commit comments