- change title to "OpenShift Command-Line Interface"
- annotate code blocks w/ ‘bash’
- mark up common flags table, adding args and rewording the description
- add command groups headings as well as linked (toc-ish) intro blurb
- use hash-at-bol instead of line of equal-signs/hyphens for heading markup
- use backtick to markup hyphen (to mean stdin)
- remove noisy ‘Examples’ headings
- remove back-to-back codeblock, moving first one inline into intro blurb
- rework some intro blurbs for consistency: "This DOES-SOMETHING..."
- zonk ‘oc namespace’ (per https://github.com/openshift/origin/issues/3165#issuecomment-114315963)
- do ‘s/oc update/oc replace/g’
- (oc login): add description, example
- (oc logout): add description
- (oc whoami): add description, example, "see also"
- (oc volume): add description, example
- (oc env): add description, example
- (oc config): add intro, general form, subcommands table, example
- (oc export): add description, options table, example
- (oc import-image): add description, example
- (oc deploy): add description, options table, examples
- (oc rollback): add description, options table, examples
- (oc new-build): add description, component table, options table, example
- (oc cancel-build): add description, options table, example
- (oc tag): add description, example
- (oc edit): add description, options table, example
- (oc exec): add description and examples
- (oc port-forward): add description and examples
- (oc proxy): add description, option table and example
- (oc new-project): add description, example
- (oc start-build): simplify build names in example; add "see also"
- (oc new-app): add description, options table, example, "see also"
- (oc status): add description, "see also"
- (oc project): add description, example
- (oc build-logs): update link text to say "kubectl logs"; remove deprecation note
- (oc get): add "see also"
- (oc describe): convert simple ref to xref
- (oc patch): add description, examples
| ... | ... |
@@ -1,52 +1,362 @@ |
| 1 |
-oc command line interface |
|
| 2 |
-============================== |
|
| 1 |
+# OpenShift Command-Line Interface |
|
| 3 | 2 |
|
| 4 | 3 |
The `oc` command line tool is used to interact with the [OpenShift](http://openshift.github.io) and [Kubernetes](http://kubernetes.io/) HTTP API(s). `oc` is an alias for `openshift cli`. |
| 5 | 4 |
|
| 6 |
-`oc` is *verb focused*. The base verbs are *[get](#oc-get)*, *[create](#oc-create)*, *[delete](#oc-delete)*, |
|
| 7 |
-*[update](#oc-update)*, and *[describe](#oc-describe)*. These verbs can be used to manage both Kubernetes and |
|
| 8 |
-OpenShift resources. |
|
| 9 |
- |
|
| 10 |
-Some verbs support the `-f` flag, which accepts regular file path, URL or '-' for |
|
| 5 |
+`oc` is *verb focused*. |
|
| 6 |
+The base verbs are *[get](#oc-get)*, *[create](#oc-create)*, *[delete](#oc-delete)*, *[replace](#oc-replace)*, and *[describe](#oc-describe)*. |
|
| 7 |
+These verbs can be used to manage both Kubernetes and OpenShift resources. |
|
| 8 |
+Overall, there are six command groups: |
|
| 9 |
+[basic](#basic-commands), |
|
| 10 |
+[build and deploy](#build-and-deploy-commands), |
|
| 11 |
+[application modification](#application-modification-commands), |
|
| 12 |
+[troubleshooting and debugging](#troubleshooting-and-debugging-commands), |
|
| 13 |
+[advanced](#advanced-commands), |
|
| 14 |
+and [settings](#settings-commands). |
|
| 15 |
+ |
|
| 16 |
+Some verbs support the `-f` flag, which accepts regular file path, URL or `-` for |
|
| 11 | 17 |
the standard input. For most actions, both JSON and YAML file formats are |
| 12 | 18 |
supported. |
| 13 | 19 |
|
| 14 | 20 |
Use `oc --help` for a full list of the verbs and subcommands available. A detailed list of examples for the most common verbs and subcommands is documented in the [oc by example](./generated/oc_by_example_content.adoc) and [oadm by example](./generated/oc_by_example_content.adoc) documents. |
| 15 | 21 |
|
| 16 |
-Common Flags |
|
| 22 |
+## Common Flags |
|
| 17 | 23 |
|
| 18 | 24 |
CLI commands support both local (specific to the given command) and global (works for every command available) flags. Some of the most common global flags are: |
| 19 | 25 |
|
| 20 | 26 |
| Name | Description | |
| 21 |
-|:-------------------------- |:--------------------------------------------------------| |
|
| 22 |
-| --namespace (-n) | Namespace scope for the CLI request (default 'default') | |
|
| 23 |
-| --ns-path | Path to a file with the default namespace | |
|
| 24 |
-| --match-server-version | Require server version to match client version | |
|
| 25 |
-| --loglevel | Set the log verbosity level between 0-5 (default '0') | |
|
| 26 |
-| --server (-s) | API server to connect to | |
|
| 27 |
-| --client-certificate | Path to a client certificate for TLS | |
|
| 28 |
-| --client-key | Path to a client key file for TLS | |
|
| 29 |
-| --certificate-authority | Path to a CA certificate file | |
|
| 30 |
-| --auth-path | Path to the auth info file (used for HTTPS) | |
|
| 31 |
-| --api-version | The version of the API to use against the server | |
|
| 32 |
-| --insecure-skip-tls-verify | Skip SSL certificate validation (will make HTTPS insecure) | |
|
| 33 |
-| --help (-h) | Display help for specified command | |
|
| 27 |
+|:---------------------------|:--------------------------------------------------------| |
|
| 28 |
+|`--namespace` (`-n`) *ns* | Use *ns* as the namespace scope for the CLI request (default `default`). | |
|
| 29 |
+|`--ns-path` *filename* | Look in *filename* for the default namespace. | |
|
| 30 |
+|`--match-server-version` | Require server version to match client version. | |
|
| 31 |
+|`--loglevel` *n* | Set the log verbosity level to *n* (between 0-5, default 0). | |
|
| 32 |
+|`--server` (`-s`) *host* | Connect to *host* for API service. | |
|
| 33 |
+|`--client-certificate` *filename* | Look in *filename* for the TLS client certificate. | |
|
| 34 |
+|`--client-key` *filename* | Look in *filename* for the TLS client key. | |
|
| 35 |
+|`--certificate-authority` *filename* | Look in *filename* for the CA certificate. | |
|
| 36 |
+|`--auth-path` *filename* | Look in *filename* for the auth info (for HTTPS). | |
|
| 37 |
+|`--api-version` *version* | Specify API version *version* to use against the server. | |
|
| 38 |
+|`--insecure-skip-tls-verify` | Skip SSL certificate validation (makes HTTPS insecure). | |
|
| 39 |
+|`--help` (`-h`) | Display help for the specified command. | |
|
| 34 | 40 |
|
| 35 | 41 |
Use `oc options` for a full list of all global flags available. |
| 36 | 42 |
|
| 37 |
-oc get |
|
| 43 |
+## Basic Commands |
|
| 44 |
+ |
|
| 45 |
+### oc |
|
| 46 |
+ |
|
| 47 |
+This displays the list of available commands. |
|
| 48 |
+ |
|
| 49 |
+### oc login |
|
| 50 |
+ |
|
| 51 |
+This retrieves a session token that allows you to act as a user. |
|
| 52 |
+Invoked without arguments, `oc login` prompts for a username and a password. |
|
| 53 |
+For example, these two invocations are identical: |
|
| 54 |
+ |
|
| 55 |
+```bash |
|
| 56 |
+$ oc login |
|
| 57 |
+Username: test |
|
| 58 |
+Password: test |
|
| 59 |
+ |
|
| 60 |
+$ oc login -u test -p test |
|
| 61 |
+``` |
|
| 62 |
+ |
|
| 63 |
+See also [`oc logout`](#oc-logout) and [`oc whoami`](#oc-whoami). |
|
| 64 |
+ |
|
| 65 |
+### oc new-project |
|
| 66 |
+ |
|
| 67 |
+This creates a new project, with the currently logged-in user as the project admin. |
|
| 68 |
+Option `--display-name` specifies the user-facing name of the project. |
|
| 69 |
+Option `--description` specifies its description. |
|
| 70 |
+ |
|
| 71 |
+For example: |
|
| 72 |
+ |
|
| 73 |
+```bash |
|
| 74 |
+$ oc new-project web-team-dev \ |
|
| 75 |
+ --display-name="Web Team Development" \ |
|
| 76 |
+ --description="Development project for the web team." |
|
| 77 |
+``` |
|
| 78 |
+ |
|
| 79 |
+Note that we use double-quotes around the option arguments. |
|
| 80 |
+ |
|
| 81 |
+### oc new-app |
|
| 82 |
+ |
|
| 83 |
+This creates a new application in OpenShift with the specified source code, templates, and images. |
|
| 84 |
+It builds up the components of an application using images, templates, or code that has a public repository. |
|
| 85 |
+It looks up images on the local Docker installation (if available), a Docker registry, or an OpenShift image stream. |
|
| 86 |
+If you specify a source code URL, it sets up a build that takes the source code and converts it into an image that can run in a pod. |
|
| 87 |
+Local source must be in a git repository that has a remote repository that the OpenShift instance can see. |
|
| 88 |
+The images will be deployed via a deployment configuration, and a service will be connected to the first public port of the app. |
|
| 89 |
+You may either specify components using the various existing flags or let new-app autodetect what kind of components you have provided. |
|
| 90 |
+ |
|
| 91 |
+If you provide source code, you may need to run a build with `oc start-build` after the application is created. |
|
| 92 |
+ |
|
| 93 |
+The general form is: |
|
| 94 |
+ |
|
| 95 |
+```bash |
|
| 96 |
+$ oc new-app <component> [options] |
|
| 97 |
+``` |
|
| 98 |
+ |
|
| 99 |
+where *component* is the same as for [`oc new-build`](#oc-new-build). |
|
| 100 |
+The options are: |
|
| 101 |
+ |
|
| 102 |
+| Option | Description | |
|
| 103 |
+|:-----------------------------|:---------------------------------------------------| |
|
| 104 |
+|`--code` *dir* | Use source code in *dir* | |
|
| 105 |
+|`--context-dir` *dir* | Use *dir* as context dir in the build | |
|
| 106 |
+|`--docker-image` *image* | Include Docker image *image* in the app | |
|
| 107 |
+|`--env` (`-e`) *k1=v1,...* | Set env vars *k1...* to values *v1...* | |
|
| 108 |
+|`--file` *filename* | Use template in *filename* | |
|
| 109 |
+|`--group` *comp1*`+`*comp2* | Group together components *comp1* and *comp2* | |
|
| 110 |
+|`--image-stream` (`-i`) *is* | Use imagestream *is* in the app | |
|
| 111 |
+|`--insecure-registry` | Bypass cert checks for referenced Docker images | |
|
| 112 |
+|`--labels` (`-l`) *k1=v1,...* | Label all resources with *k1=v1,...* | |
|
| 113 |
+|`--name` *name* | Give *name* to all generated app artifacts | |
|
| 114 |
+|`--no-headers` | For default output, don't print headers | |
|
| 115 |
+|`--output-template` *s* | Template string (`-o template`) or path (`-o templatefile`) | |
|
| 116 |
+|`--output-version` *version* | Output with *version* (default api-version) | |
|
| 117 |
+|`--output` (`-o`) *format* | *format* is one of: `json`, `yaml`, `template`, `templatefile` | |
|
| 118 |
+|`--param` (`-p`) *k1=v1,...* | Set/override parameters *k1...* with *v1...* | |
|
| 119 |
+|`--strategy` *s* | Use build strategy *s*, one of: `docker`, `source` | |
|
| 120 |
+|`--template` *t* | Use OpenShift stored template *t* in the app | |
|
| 121 |
+ |
|
| 122 |
+The template format is [golang templates](http://golang.org/pkg/text/template/#pkg-overview). |
|
| 123 |
+The following example uses a MySQL image in a private registry to create an app and override application artifacts' names. |
|
| 124 |
+ |
|
| 125 |
+```bash |
|
| 126 |
+$ oc new-app \ |
|
| 127 |
+ --docker-image=myregistry.com/mycompany/mysql \ |
|
| 128 |
+ --name=private |
|
| 129 |
+``` |
|
| 130 |
+ |
|
| 131 |
+See also [`oc start-build`](#oc-start-build). |
|
| 132 |
+ |
|
| 133 |
+### oc status |
|
| 134 |
+ |
|
| 135 |
+This shows a high level overview of the current project. |
|
| 136 |
+ |
|
| 137 |
+See also [`oc describe`](#oc-describe) and [`oc get`](#oc-get). |
|
| 138 |
+ |
|
| 139 |
+### oc project |
|
| 140 |
+ |
|
| 141 |
+This displays the current project, or switches to another one. |
|
| 142 |
+ |
|
| 143 |
+For example: |
|
| 144 |
+ |
|
| 145 |
+```bash |
|
| 146 |
+# Switch to the myapp project |
|
| 147 |
+$ oc project myapp |
|
| 148 |
+ |
|
| 149 |
+# Display the project currently in use |
|
| 150 |
+$ oc project |
|
| 151 |
+``` |
|
| 152 |
+ |
|
| 153 |
+## Build and Deploy Commands |
|
| 154 |
+ |
|
| 155 |
+### oc start-build |
|
| 156 |
+ |
|
| 157 |
+This manually starts a build, using either the specified buildConfig or a build name with the `--from-build` option. |
|
| 158 |
+There is also the option of streaming |
|
| 159 |
+the logs of the build if the `--follow` flag is specified. |
|
| 160 |
+ |
|
| 161 |
+```bash |
|
| 162 |
+$ oc start-build ruby-sample-build |
|
| 163 |
+$ oc start-build --from-build=ruby-sample-build-1 |
|
| 164 |
+$ oc start-build --from-build=ruby-sample-build-1 --follow |
|
| 165 |
+``` |
|
| 166 |
+ |
|
| 167 |
+See also [`oc new-build`](#oc-new-build) and [`oc new-app`](#oc-new-app). |
|
| 168 |
+ |
|
| 169 |
+### oc build-logs |
|
| 170 |
+ |
|
| 171 |
+This retrieves the logs from a Build container. |
|
| 172 |
+It allows you to |
|
| 173 |
+debug broken Build. |
|
| 174 |
+If the build is still running, this streams the logs from the container to console. |
|
| 175 |
+Use `oc get builds` to obtain a list of builds. |
|
| 176 |
+ |
|
| 177 |
+```bash |
|
| 178 |
+$ oc build-logs rubyapp-build |
|
| 179 |
+``` |
|
| 180 |
+ |
|
| 181 |
+### oc deploy |
|
| 182 |
+ |
|
| 183 |
+This views, starts, cancels or retries deployments. |
|
| 184 |
+The general form is: |
|
| 185 |
+ |
|
| 186 |
+```bash |
|
| 187 |
+$ oc deploy <deployment-config> [options] |
|
| 188 |
+``` |
|
| 189 |
+ |
|
| 190 |
+If invoked without options, `oc deploy` displays the latest deployment for the specified *deployment-config*. |
|
| 191 |
+For example: |
|
| 192 |
+ |
|
| 193 |
+```bash |
|
| 194 |
+$ oc deploy database |
|
| 195 |
+``` |
|
| 196 |
+ |
|
| 197 |
+| Option | Description | |
|
| 198 |
+|:----------|-------------| |
|
| 199 |
+|`--latest` | Start a deployment. | |
|
| 200 |
+|`--retry` | Retry the latest failed deployment. | |
|
| 201 |
+|`--cancel` | Cancel the in-progress deployment. | |
|
| 202 |
+ |
|
| 203 |
+The following example shows how to cancel the `database` deployment: |
|
| 204 |
+ |
|
| 205 |
+```bash |
|
| 206 |
+$ oc deploy database --cancel |
|
| 207 |
+``` |
|
| 208 |
+ |
|
| 209 |
+### oc rollback |
|
| 210 |
+ |
|
| 211 |
+This reverts the pod and container configuration back to a previous deployment. |
|
| 212 |
+Scaling and trigger settings are normally left as-is. |
|
| 213 |
+The general form is: |
|
| 214 |
+ |
|
| 215 |
+```bash |
|
| 216 |
+$ oc rollback <deployment> [options] |
|
| 217 |
+``` |
|
| 218 |
+ |
|
| 219 |
+The options are: |
|
| 220 |
+ |
|
| 221 |
+| Option | Description | |
|
| 222 |
+|:----------------------------|:------------| |
|
| 223 |
+|`--dry-run` | Display what the rollback *would do* but do not perform the rollback. | |
|
| 224 |
+|`--change-triggers` | Include the previous deployment's triggers in the rollback. | |
|
| 225 |
+|`--change-strategy` | Include the previous deployment's strategies in the rollback. | |
|
| 226 |
+|`--change-scaling-settings` | Include the previous deployment's replication controller replica count and selector in the rollback. | |
|
| 227 |
+|`--output` *format* | Do not roll back; instead, display updated deployment configuration in the specified *format*, one of: `json`, `yaml`, `template`, `templatefile`. | |
|
| 228 |
+|`-t` *template-string* | Use *template-string* (with `--output template`). | |
|
| 229 |
+|`-t` *filename* | Write to *filename* (with `--output templatefile`). | |
|
| 230 |
+ |
|
| 231 |
+The *template-string* is in [golang template](http://golang.org/pkg/text/template) format. |
|
| 232 |
+Here are two examples: |
|
| 233 |
+ |
|
| 234 |
+```bash |
|
| 235 |
+# Perform a rollback. |
|
| 236 |
+$ oc rollback deployment-1 |
|
| 237 |
+ |
|
| 238 |
+# Perform the rollback "manually" by piping back to "oc replace". |
|
| 239 |
+$ oc rollback deployment-1 --output=json | oc replace dc deployment -f - |
|
| 240 |
+``` |
|
| 241 |
+ |
|
| 242 |
+See also [`oc replace`](#oc-replace). |
|
| 243 |
+ |
|
| 244 |
+### oc new-build |
|
| 245 |
+ |
|
| 246 |
+This creates a new build with the specified source code. |
|
| 247 |
+It creates a build configuration for your application using images and code that has a public repository. |
|
| 248 |
+It looks up the images on the local Docker installation (if available), a Docker registry, or an OpenShift image stream. |
|
| 249 |
+If you specify a source code URL, it sets up a build that takes the source code and converts it into an image that can run inside a pod. |
|
| 250 |
+Local source must be in a git repository that has a remote repository that the OpenShift instance can see. |
|
| 251 |
+ |
|
| 252 |
+Once the build configuration is created you may need to run a build with `oc start-build`. |
|
| 253 |
+ |
|
| 254 |
+The general form is: |
|
| 255 |
+ |
|
| 256 |
+```bash |
|
| 257 |
+$ oc new-build <component> [options] |
|
| 258 |
+``` |
|
| 259 |
+ |
|
| 260 |
+where *component* has one of the forms: |
|
| 261 |
+ |
|
| 262 |
+| Form | Description | |
|
| 263 |
+|:----------------|:----------------------| |
|
| 264 |
+| *image* | Use *image* directly. | |
|
| 265 |
+| *imagestream* | Use the latest image in *imagestream*. | |
|
| 266 |
+| *path* | Use source code found at *path*. | |
|
| 267 |
+| *url* | Use source code found at *url*. | |
|
| 268 |
+| *image*~*url* | Note the tilde `~` between *image* and *url*. In this case the component is actually made of two sub-components, the *image* and the source code found at *url*. Use the image as the base and arrange to build the source code on it. | |
|
| 269 |
+ |
|
| 270 |
+The options are: |
|
| 271 |
+ |
|
| 272 |
+| Option | Description | |
|
| 273 |
+|:-----------------------------------|:-----------------------------------------------------| |
|
| 274 |
+|`--code` | | |
|
| 275 |
+|`--image` (`-i`) *repository* | Find the specified image in *repository*. | |
|
| 276 |
+|`--labels` (`-l`) *k1=v1,k2=v2,...* | Add labels *k1=v1,k2=v2,...* to all created objects. | |
|
| 277 |
+|`--strategy` *s* | Use strategy *s* (one of: `docker`, `source`). | |
|
| 278 |
+|`--to-docker` | Force the build output to be `DockerImage`. | |
|
| 279 |
+|`--name` *name* | Give generated build artifacts the name *name*. | |
|
| 280 |
+ |
|
| 281 |
+The following example creates a NodeJS buildConfig based on the provided image / source code combination: |
|
| 282 |
+ |
|
| 283 |
+```bash |
|
| 284 |
+$ oc new-build openshift/nodejs-010-centos7~https://bitbucket.com/user/nodejs-app |
|
| 285 |
+``` |
|
| 286 |
+ |
|
| 287 |
+See also [`oc start-build`](#oc-start-build) and [`oc new-app`](#oc-new-app). |
|
| 288 |
+ |
|
| 289 |
+### oc cancel-build |
|
| 290 |
+ |
|
| 291 |
+This cancels a pending or running build. |
|
| 292 |
+The general form is: |
|
| 293 |
+ |
|
| 294 |
+```bash |
|
| 295 |
+$ oc cancel-build <build> [options] |
|
| 296 |
+``` |
|
| 297 |
+ |
|
| 298 |
+The options are: |
|
| 299 |
+ |
|
| 300 |
+| Option | Description | |
|
| 301 |
+|:-------------|:------------| |
|
| 302 |
+|`--dump-logs` | Display the build logs for the cancelled build. | |
|
| 303 |
+|`--restart` | Create a new build after the current build is cancelled. | |
|
| 304 |
+ |
|
| 305 |
+The following example cancels the build named `1da32cvq` and restarts it. |
|
| 306 |
+ |
|
| 307 |
+```bash |
|
| 308 |
+$ oc cancel-build 1da32cvq --restart |
|
| 309 |
+``` |
|
| 310 |
+ |
|
| 311 |
+See also [`oc new-build`](#oc-new-build). |
|
| 312 |
+ |
|
| 313 |
+### oc import-image |
|
| 38 | 314 |
|
| 39 |
-This command can be used for displaying one or many resources. Possible |
|
| 315 |
+This imports tag and image information from an external Docker image registry. |
|
| 316 |
+For example, the following command imports from the `mystream` registry. |
|
| 317 |
+ |
|
| 318 |
+```bash |
|
| 319 |
+$ oc import-image mystream |
|
| 320 |
+``` |
|
| 321 |
+ |
|
| 322 |
+### oc scale |
|
| 323 |
+ |
|
| 324 |
+This sets a new size for a Replication Controller either directly or via its Deployment Configuration. |
|
| 325 |
+ |
|
| 326 |
+```bash |
|
| 327 |
+# n is the highest deployment number for the dc ruby-hello-world |
|
| 328 |
+$ oc scale rc ruby-hello-world-n --replicas=3 |
|
| 329 |
+$ oc scale dc ruby-hello-world --current-replicas=3 --replicas=5 |
|
| 330 |
+``` |
|
| 331 |
+ |
|
| 332 |
+### oc tag |
|
| 333 |
+ |
|
| 334 |
+This tags existing images into one or more image streams. |
|
| 335 |
+The option `--source` is a hint for the source type; its value is one of: `imagestreamtag`, `istag`, `imagestreamimage`, `isimage`, and `docker`. |
|
| 336 |
+The general form is: |
|
| 337 |
+ |
|
| 338 |
+```bash |
|
| 339 |
+$ oc tag [--source=<sourcetype>] <source> <dest> [<dest> ...] |
|
| 340 |
+``` |
|
| 341 |
+ |
|
| 342 |
+For example: |
|
| 343 |
+ |
|
| 344 |
+```bash |
|
| 345 |
+$ oc tag --source=docker openshift/origin:latest myproject/ruby:tip |
|
| 346 |
+``` |
|
| 347 |
+ |
|
| 348 |
+## Application Modification Commands |
|
| 349 |
+ |
|
| 350 |
+### oc get |
|
| 351 |
+ |
|
| 352 |
+This displays one or many resources. |
|
| 353 |
+Possible |
|
| 40 | 354 |
resources are all OpenShift resources (builds, buildConfigs, deployments, |
| 41 | 355 |
deploymentConfigs, images, imageRepositories, routes, projects, and others) and |
| 42 | 356 |
all Kubernetes resources (pods, replicationControllers, services, minions, |
| 43 | 357 |
events). |
| 44 | 358 |
|
| 45 |
-#### Examples |
|
| 46 |
- |
|
| 47 |
-``` |
|
| 359 |
+```bash |
|
| 48 | 360 |
$ oc get pods |
| 49 | 361 |
$ oc get replicationController 1234-56-7890-234234-456456 |
| 50 | 362 |
$ oc get service database |
| ... | ... |
@@ -55,8 +365,8 @@ $ oc get -f json pods |
| 55 | 55 |
|
| 56 | 56 |
#### Output formatting |
| 57 | 57 |
|
| 58 |
-You can control the output format by using the `-o format` flag. By default, |
|
| 59 |
-`oc` uses human-friendly printer format for console. You can also |
|
| 58 |
+You can control the output format by using the `-o format` flag. By default, |
|
| 59 |
+`oc` uses human-friendly printer format for console. You can also |
|
| 60 | 60 |
control what API version will be used to print the resource by using the |
| 61 | 61 |
`--output-version` flag. By default, it uses the latest API version. |
| 62 | 62 |
|
| ... | ... |
@@ -71,7 +381,7 @@ Available formats include: |
| 71 | 71 |
|
| 72 | 72 |
An example of using `-o template` to retrieve the *name* of the first build: |
| 73 | 73 |
|
| 74 |
-``` |
|
| 74 |
+```bash |
|
| 75 | 75 |
$ oc get builds -o template -t "{{with index .items 0}}{{.metadata.name}}{{end}}"
|
| 76 | 76 |
``` |
| 77 | 77 |
|
| ... | ... |
@@ -80,192 +390,351 @@ $ oc get builds -o template -t "{{with index .items 0}}{{.metadata.name}}{{end}}
|
| 80 | 80 |
`oc get` provides also *selectors* that you can use to filter the output |
| 81 | 81 |
by applying key-value pairs that will be matched with the resource labels: |
| 82 | 82 |
|
| 83 |
-``` |
|
| 83 |
+```bash |
|
| 84 | 84 |
$ oc get pods -s template=production |
| 85 | 85 |
``` |
| 86 | 86 |
|
| 87 |
-This command will return only pods whose `labels` include `"template": "production"` |
|
| 87 |
+This command will return only pods whose `labels` include `"template": "production"`. |
|
| 88 | 88 |
|
| 89 |
-oc create |
|
| 89 |
+See also [`oc describe`](#oc-describe). |
|
| 90 | 90 |
|
| 91 |
-This command can be used to create resources. It does not require pointers about |
|
| 92 |
-what resource it should create because it reads it from the provided JSON/YAML. |
|
| 93 |
-After successful creation, the resource name will be printed to the console. |
|
| 91 |
+### oc describe |
|
| 94 | 92 |
|
| 95 |
-#### Examples |
|
| 93 |
+This functions similar to [`oc get`](#oc-get), but also includes other information related to the specified resource. |
|
| 96 | 94 |
|
| 95 |
+```bash |
|
| 96 |
+$ oc describe service frontend |
|
| 97 | 97 |
``` |
| 98 |
-$ oc create -f pod.json |
|
| 99 |
-$ cat pod.json | oc create -f - |
|
| 100 |
-$ oc create -f http://server/pod.json |
|
| 98 |
+ |
|
| 99 |
+### oc edit |
|
| 100 |
+ |
|
| 101 |
+This starts an editor opened to the YAML representation of the specified object. |
|
| 102 |
+When the editor exits, the object is updated. |
|
| 103 |
+You can specify the editor through environment variables `OC_EDITOR`, `GIT_EDITOR`, or `EDITOR`. |
|
| 104 |
+If none of those are set, `oc edit` uses the `vi` program. |
|
| 105 |
+The general form is: |
|
| 106 |
+ |
|
| 107 |
+```bash |
|
| 108 |
+$ oc edit <resource-type>/<name> [options] |
|
| 101 | 109 |
``` |
| 102 | 110 |
|
| 103 |
-oc update |
|
| 111 |
+The options are: |
|
| 104 | 112 |
|
| 105 |
-This command can be used to update existing resources. |
|
| 113 |
+| Option | Description | |
|
| 114 |
+|:----------------------------|:--------------------------------------------------| |
|
| 115 |
+|`--output` (`-o`) *format* | Edit object as *format*, one of: `json`, `yaml`. | |
|
| 116 |
+|`--output-version` *version* | Use API version *version*. | |
|
| 106 | 117 |
|
| 107 |
-#### Examples |
|
| 118 |
+For example, to edit the service `docker-registry` in JSON using the `v1` API format: |
|
| 108 | 119 |
|
| 120 |
+```bash |
|
| 121 |
+$ oc edit svc/docker-registry --output-version=v1 -o json |
|
| 122 |
+``` |
|
| 123 |
+ |
|
| 124 |
+### oc env |
|
| 125 |
+ |
|
| 126 |
+This updates the environment on a resource with a pod template. |
|
| 127 |
+The general form is: |
|
| 128 |
+ |
|
| 129 |
+```bash |
|
| 130 |
+$ oc env <resource-type>/<name> <k1>=<v1> <k2>=<v2> |
|
| 109 | 131 |
``` |
| 110 |
-$ oc update -f pod.json |
|
| 111 |
-$ cat pod.json | oc update -f - |
|
| 112 |
-$ oc update -f http://server/pod.json |
|
| 132 |
+ |
|
| 133 |
+For example: |
|
| 134 |
+ |
|
| 135 |
+```bash |
|
| 136 |
+$ oc env dc/app DB_USER=user DB_PASS=pass |
|
| 113 | 137 |
``` |
| 114 | 138 |
|
| 115 |
-oc delete |
|
| 139 |
+### oc volume |
|
| 140 |
+ |
|
| 141 |
+This controls the storage associated with various resources. |
|
| 142 |
+The general form is: |
|
| 116 | 143 |
|
| 117 |
-This command deletes a specified resource. |
|
| 144 |
+```bash |
|
| 145 |
+$ oc volume <resource-type>/<name> --<action> <options> |
|
| 146 |
+``` |
|
| 118 | 147 |
|
| 119 |
-#### Examples |
|
| 148 |
+where *action* is one of `add`, `remove`, `list` and *options* depends on *action*. |
|
| 149 |
+For example, to arrange for the deployment configuration `registry` to access the host *_/opt_* directory, use: |
|
| 120 | 150 |
|
| 151 |
+```bash |
|
| 152 |
+$ oc volume dc/registry --add --mount-path=/opt |
|
| 121 | 153 |
``` |
| 122 |
-$ oc delete -f pod.json |
|
| 123 |
-$ oc delete pod 1234-56-7890-234234-456456 |
|
| 154 |
+ |
|
| 155 |
+### oc label |
|
| 156 |
+ |
|
| 157 |
+This adds labels to a provided resource. |
|
| 158 |
+It can also overwrite the existing labels by using the `--overwrite` flag. |
|
| 159 |
+ |
|
| 160 |
+```bash |
|
| 161 |
+$ oc label service frontend foo=bar |
|
| 124 | 162 |
``` |
| 125 | 163 |
|
| 126 |
-oc describe |
|
| 164 |
+### oc expose |
|
| 127 | 165 |
|
| 128 |
-This command is a wordier version of `oc get` which also integrates other |
|
| 129 |
-information that's related to a given resource. |
|
| 166 |
+This exposes containers internally as services or externally via routes. There is also |
|
| 167 |
+the ability to expose a deployment config, replication controller, service, |
|
| 168 |
+or pod as a new service on a specified port. If no labels are specified, |
|
| 169 |
+the new object will re-use the labels from the object it exposes. |
|
| 130 | 170 |
|
| 131 |
-#### Examples |
|
| 171 |
+```bash |
|
| 172 |
+# Expose a service as a route |
|
| 173 |
+$ oc expose service frontend |
|
| 174 |
+# Expose a deployment config as a service and use the specified port and name |
|
| 175 |
+$ oc expose dc ruby-hello-world --port=8080 --name=myservice --generator=service/v1 |
|
| 176 |
+``` |
|
| 177 |
+ |
|
| 178 |
+### oc stop |
|
| 132 | 179 |
|
| 180 |
+This gracefully shuts down a resource by id or filename. |
|
| 181 |
+It attempts to shut down and delete a resource that supports graceful termination. |
|
| 182 |
+If the resource is resizable, it will be resized to 0 before deletion. |
|
| 183 |
+ |
|
| 184 |
+```bash |
|
| 185 |
+$ oc stop service frontend |
|
| 133 | 186 |
``` |
| 134 |
-$ oc describe service frontend |
|
| 187 |
+ |
|
| 188 |
+### oc delete |
|
| 189 |
+ |
|
| 190 |
+This deletes a specified resource. |
|
| 191 |
+ |
|
| 192 |
+```bash |
|
| 193 |
+$ oc delete -f pod.json |
|
| 194 |
+$ oc delete pod 1234-56-7890-234234-456456 |
|
| 135 | 195 |
``` |
| 136 | 196 |
|
| 137 |
-oc label |
|
| 197 |
+## Troubleshooting and Debugging Commands |
|
| 138 | 198 |
|
| 139 |
-This command adds labels to a provided resource. |
|
| 140 |
-It can also overwrite the existing labels by using the `--overwrite` flag. |
|
| 199 |
+### oc logs |
|
| 141 | 200 |
|
| 142 |
-#### Examples |
|
| 201 |
+This dumps the logs from a given Pod container. |
|
| 202 |
+Use `oc get pod <pod-id>` to list the containers from a Pod. |
|
| 143 | 203 |
|
| 204 |
+```bash |
|
| 205 |
+$ oc logs frontend-pod mysql-container |
|
| 144 | 206 |
``` |
| 145 |
-$ oc label service frontend foo=bar |
|
| 207 |
+ |
|
| 208 |
+### oc exec |
|
| 209 |
+ |
|
| 210 |
+This executes a command in a container. |
|
| 211 |
+The general form is one of: |
|
| 212 |
+ |
|
| 213 |
+```bash |
|
| 214 |
+$ oc exec -p <pod> [-c <container>] <command> |
|
| 215 |
+$ oc exec -p <pod> [-c <container>] [-i] [-t] -- <command> [args...] |
|
| 146 | 216 |
``` |
| 147 | 217 |
|
| 148 |
-oc stop |
|
| 218 |
+If `-c <container>` is omitted, OpenShift chooses the first container in the pod. |
|
| 219 |
+The `-i` (or `--stdin`) flag passes local stdin to the container. |
|
| 220 |
+The `-t` (or `--tty`) flag arranges for stdin to be a TTY. |
|
| 149 | 221 |
|
| 150 |
-This command gracefully shuts down a resource by id or filename. |
|
| 151 |
-It attempts to shut down and delete a resource that supports graceful termination. |
|
| 152 |
-If the resource is resizable, it will be resized to 0 before deletion. |
|
| 222 |
+Some examples are: |
|
| 153 | 223 |
|
| 154 |
-#### Examples |
|
| 224 |
+```bash |
|
| 225 |
+# Get output from running 'date' in 'ruby-container' from pod 123456-7890. |
|
| 226 |
+$ oc exec -p 123456-7890 -c ruby-container date |
|
| 155 | 227 |
|
| 228 |
+# Switch to raw terminal mode, attach stdin to 'bash' in 'ruby-container' |
|
| 229 |
+# from pod 123456-780, and stdout/stderr from 'bash' back to the client. |
|
| 230 |
+$ oc exec -p 123456-7890 -c ruby-container -i -t -- bash -il |
|
| 156 | 231 |
``` |
| 157 |
-$ oc stop service frontend |
|
| 232 |
+ |
|
| 233 |
+### oc port-forward |
|
| 234 |
+ |
|
| 235 |
+This forwards one or more local ports to a pod. |
|
| 236 |
+The general form is: |
|
| 237 |
+ |
|
| 238 |
+```bash |
|
| 239 |
+$ oc port-forward -p <pod> <forwarding-spec> [...] |
|
| 158 | 240 |
``` |
| 159 | 241 |
|
| 160 |
-oc namespace |
|
| 242 |
+where *forwarding-spec* is either a single port (integer), or a pair of ports separated by a colon `<outside>:<inside>`. |
|
| 243 |
+If *outside* is omitted or zero, OpenShift chooses a random port as the effective listening port. |
|
| 244 |
+ |
|
| 245 |
+Some examples are: |
|
| 161 | 246 |
|
| 162 |
-This command sets the default namespace used for all `oc` commands. |
|
| 247 |
+```bash |
|
| 248 |
+# Listen on ports 5000 and 6000 locally, forwarding data |
|
| 249 |
+# to/from ports 5000 and 6000 in the pod. |
|
| 250 |
+$ oc port-forward -p mypod 5000 6000 |
|
| 163 | 251 |
|
| 164 |
-#### Examples |
|
| 252 |
+# Listen on 8888 locally, forwarding to 5000 in the pod. |
|
| 253 |
+$ oc port-forward -p mypod 8888:5000 |
|
| 165 | 254 |
|
| 166 |
-``` |
|
| 167 |
-$ oc namespace myuser |
|
| 255 |
+# Listen on a random port locally, forwarding to 5000 in the pod. |
|
| 256 |
+# (These invocations are equivalent.) |
|
| 257 |
+$ oc port-forward -p mypod :5000 |
|
| 258 |
+$ oc port-forward -p mypod 0:5000 |
|
| 168 | 259 |
``` |
| 169 | 260 |
|
| 170 |
-oc logs |
|
| 261 |
+### oc proxy |
|
| 171 | 262 |
|
| 172 |
-This command dumps the logs from a given Pod container. You can list the |
|
| 173 |
-containers from a Pod using the following command: |
|
| 263 |
+This runs a proxy to the Kubernetes API server. |
|
| 264 |
+By default, the proxy listens on port 8001. |
|
| 265 |
+API endpoints are served under directory `/api/` and any static files are served under directory `/static/`. |
|
| 266 |
+The general form is: |
|
| 174 | 267 |
|
| 268 |
+```bash |
|
| 269 |
+$ oc proxy [options] |
|
| 175 | 270 |
``` |
| 176 |
-$ oc get -o yaml pod POD_ID |
|
| 271 |
+ |
|
| 272 |
+The options are: |
|
| 273 |
+ |
|
| 274 |
+| Option | Description | |
|
| 275 |
+|:---------------------------|:------------| |
|
| 276 |
+|`--port` (`-p`) *n* | Listen on port *n*. | |
|
| 277 |
+|`--api-prefix` *dir* | Serve the proxied API under *dir*. | |
|
| 278 |
+|`--www` (`-w`) | Enable serving static files. | |
|
| 279 |
+|`--www-prefix` (`-P`) *dir* | Serve static files under *dir*. | |
|
| 280 |
+|`--disable-filter` | Disable request filtering. | |
|
| 281 |
+|`--accept-hosts` *rx* | Accept requests from hosts matching regular expression *rx*. | |
|
| 282 |
+|`--accept-paths` *rx* | Accept paths matching regular expression *rx*. | |
|
| 283 |
+|`--reject-paths` *rx* | Reject paths matching regular expression *rx*. | |
|
| 284 |
+ |
|
| 285 |
+**WARNING**: |
|
| 286 |
+The `--disable-filter` flag is dangerous and can leave you vulnerable to XSRF attacks. |
|
| 287 |
+Use with caution. |
|
| 288 |
+ |
|
| 289 |
+The following example runs a proxy on port 8011 with API prefix `k8s-api`. |
|
| 290 |
+ |
|
| 291 |
+```bash |
|
| 292 |
+$ oc proxy -p 8011 --api-prefix k8s-api |
|
| 177 | 293 |
``` |
| 178 | 294 |
|
| 179 |
-#### Examples |
|
| 295 |
+This makes, for instance, the pods API (version 1) available at `localhost:8011/k8s-api/v1/pods/`. |
|
| 296 |
+ |
|
| 297 |
+## Advanced Commands |
|
| 180 | 298 |
|
| 299 |
+### oc create |
|
| 300 |
+ |
|
| 301 |
+This creates resources. It does not require pointers about |
|
| 302 |
+what resource it should create because it reads it from the provided JSON/YAML. |
|
| 303 |
+After successful creation, the resource name will be printed to the console. |
|
| 304 |
+ |
|
| 305 |
+```bash |
|
| 306 |
+$ oc create -f pod.json |
|
| 307 |
+$ cat pod.json | oc create -f - |
|
| 308 |
+$ oc create -f http://server/pod.json |
|
| 181 | 309 |
``` |
| 182 |
-$ oc logs frontend-pod mysql-container |
|
| 310 |
+ |
|
| 311 |
+### oc replace |
|
| 312 |
+ |
|
| 313 |
+This replaces existing resources. |
|
| 314 |
+ |
|
| 315 |
+```bash |
|
| 316 |
+$ oc replace -f pod.json |
|
| 317 |
+$ cat pod.json | oc replace -f - |
|
| 318 |
+$ oc replace -f http://server/pod.json |
|
| 183 | 319 |
``` |
| 184 | 320 |
|
| 185 |
-oc expose |
|
| 321 |
+### oc patch |
|
| 186 | 322 |
|
| 187 |
-Expose containers internally as services or externally via routes. There is also |
|
| 188 |
-the ability to expose a deployment config, replication controller, service, |
|
| 189 |
-or pod as a new service on a specified port. If no labels are specified, |
|
| 190 |
-the new object will re-use the labels from the object it exposes. |
|
| 323 |
+This updates one or more fields of a resource using strategic merge patch. |
|
| 324 |
+The general form is: |
|
| 325 |
+ |
|
| 326 |
+```bash |
|
| 327 |
+$ oc patch <resource-type> <name> -p <patch> |
|
| 328 |
+``` |
|
| 191 | 329 |
|
| 330 |
+where *patch* is a JSON or YAML map expression that names one or more fields and their new values. |
|
| 331 |
+The following example sets the `spec.unschedulable` field of the `app` node to the value `true`: |
|
| 192 | 332 |
|
| 193 |
-#### Examples |
|
| 333 |
+```bash |
|
| 334 |
+$ oc patch node app -p '{"spec":{"unschedulable":true}}'
|
|
| 335 |
+``` |
|
| 336 |
+ |
|
| 337 |
+The equivalent operation with YAML is: |
|
| 194 | 338 |
|
| 195 | 339 |
```bash |
| 196 |
-# Expose a service as a route |
|
| 197 |
-$ oc expose service frontend |
|
| 198 |
-# Expose a deployment config as a service and use the specified port and name |
|
| 199 |
-$ oc expose dc ruby-hello-world --port=8080 --name=myservice --generator=service/v1 |
|
| 340 |
+$ oc patch node app -p ' |
|
| 341 |
+spec: |
|
| 342 |
+ unschedulable: true |
|
| 343 |
+' |
|
| 200 | 344 |
``` |
| 201 | 345 |
|
| 202 |
-oc process |
|
| 346 |
+In both cases, the top-level field is `spec` and its value is another map expression whose sole key is `unschedulable`. |
|
| 347 |
+ |
|
| 348 |
+### oc process |
|
| 203 | 349 |
|
| 204 |
-This command processes a Template into a valid Config resource. The processing |
|
| 350 |
+This processes a Template into a valid Config resource. The processing |
|
| 205 | 351 |
will take care of generating values for parameters specified in the Template and |
| 206 | 352 |
substituting the values in the corresponding places. An example Template can be |
| 207 | 353 |
found in [examples/sample-app/application-template-stibuild.json](https://github.com/openshift/origin/blob/master/examples/sample-app/application-template-stibuild.json). |
| 208 | 354 |
|
| 209 |
-#### Examples |
|
| 210 |
- |
|
| 211 |
-``` |
|
| 355 |
+```bash |
|
| 212 | 356 |
$ oc process -f examples/sample-app/application-template-stibuild.json > config.json |
| 213 | 357 |
$ oc process -f template.json | oc create -f - |
| 214 | 358 |
``` |
| 215 | 359 |
|
| 216 |
-oc start-build |
|
| 217 |
- |
|
| 218 |
-This command will manually start a build by specifying either a buildConfig or |
|
| 219 |
-a build name with the `--from-build` flag. There is also the option of streaming |
|
| 220 |
-the logs of the build if the `--follow` flag is specified. |
|
| 360 |
+### oc export |
|
| 221 | 361 |
|
| 222 |
-#### Examples |
|
| 362 |
+This displays to standard output the specified resource(s) in YAML format. |
|
| 363 |
+The general form is: |
|
| 223 | 364 |
|
| 224 |
-``` |
|
| 225 |
-$ oc start-build ruby-sample-build |
|
| 226 |
-$ oc start-build --from-build=ruby-sample-build-275d3373-c252-11e4-bc79-080027c5bfa9 |
|
| 227 |
-$ oc start-build --from-build=ruby-sample-build-275d3373-c252-11e4-bc79-080027c5bfa9 --follow |
|
| 365 |
+```bash |
|
| 366 |
+$ oc export <resource-type>/<name> [options] |
|
| 228 | 367 |
``` |
| 229 | 368 |
|
| 230 |
-oc scale |
|
| 369 |
+The options are: |
|
| 231 | 370 |
|
| 232 |
-This command sets a new size for a Replication Controller either directly or via its Deployment Configuration. |
|
| 371 |
+| Option | Description | |
|
| 372 |
+|:----------------------|:-------------------------------------------------| |
|
| 373 |
+|`-f` *filename* | Write to *filename* instead of standard output. | |
|
| 374 |
+|`--as-template` *name* | Output in template format with name *name*. | |
|
| 375 |
+|`--all` | Select all objects with given *resource-type*. | |
|
| 376 |
+|`--exact` | Preserve fields that may be cluster specific, such as service `portalIP`s or generated names. | |
|
| 377 |
+|`--raw` | Do not alter the resources in any way after they are loaded. | |
|
| 233 | 378 |
|
| 234 |
-#### Examples |
|
| 379 |
+The following example exports all services to a template with name `test`. |
|
| 235 | 380 |
|
| 236 | 381 |
```bash |
| 237 |
-# n is the highest deployment number for the dc ruby-hello-world |
|
| 238 |
-$ oc scale rc ruby-hello-world-n --replicas=3 |
|
| 239 |
-$ oc scale dc ruby-hello-world --current-replicas=3 --replicas=5 |
|
| 382 |
+$ oc export service --all --as-template=test |
|
| 240 | 383 |
``` |
| 241 | 384 |
|
| 242 |
-oc build-logs |
|
| 385 |
+## Settings Commands |
|
| 243 | 386 |
|
| 244 |
-> **NOTE**: This command will be later replaced by upstream (see: [kubectl log](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/kubectl_logs.md#kubectl-logs)). |
|
| 387 |
+### oc logout |
|
| 245 | 388 |
|
| 246 |
-This command will retrieve the logs from a Build container. It allows you to |
|
| 247 |
-debug broken Build. If the build is still running, this command can stream the |
|
| 248 |
-logs from the container to console. You can obtain a list of builds by using: |
|
| 389 |
+This destroys the session token, preventing further access until next login (with [`oc login`](#oc-login)). |
|
| 249 | 390 |
|
| 391 |
+### oc config |
|
| 392 |
+ |
|
| 393 |
+This manages the OpenShift [kubeconfig files](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/kubeconfig-file.md). |
|
| 394 |
+The general form is: |
|
| 395 |
+ |
|
| 396 |
+```bash |
|
| 397 |
+$ oc config <subcommand> [<arg> ...] |
|
| 250 | 398 |
``` |
| 251 |
-$ oc get builds |
|
| 252 |
-``` |
|
| 253 | 399 |
|
| 254 |
-#### Examples |
|
| 400 |
+The subcommands are: |
|
| 401 |
+ |
|
| 402 |
+| Subcommand | Description | |
|
| 403 |
+|:-----------------|:-------------------------------------------------------------------| |
|
| 404 |
+|`set` | Set an individual value in a kubeconfig file. | |
|
| 405 |
+|`set-cluster` | Set a cluster entry in kubeconfig. | |
|
| 406 |
+|`set-context` | Set a context entry in kubeconfig. | |
|
| 407 |
+|`set-credentials` | Sets a user entry in kubeconfig. | |
|
| 408 |
+|`unset` | Unset an individual value in a kubeconfig file. | |
|
| 409 |
+|`use-context` | Set the current-context in a kubeconfig file. | |
|
| 410 |
+|`view` | Display merged kubeconfig settings or a specified kubeconfig file. | |
|
| 255 | 411 |
|
| 412 |
+The following example changes the config context to use: |
|
| 413 |
+ |
|
| 414 |
+```bash |
|
| 415 |
+$ oc config use-context my-context |
|
| 256 | 416 |
``` |
| 257 |
-$ oc build-logs rubyapp-build |
|
| 417 |
+ |
|
| 418 |
+### oc whoami |
|
| 419 |
+ |
|
| 420 |
+This displays information about the current session. |
|
| 421 |
+If invoked without arguments, `oc whoami` displays the currently authenticated username. |
|
| 422 |
+Flag `-t` (or `--token`) means to instead display the session token. |
|
| 423 |
+Flag `-c` (or `--context`) means to instead display the user context name. |
|
| 424 |
+ |
|
| 425 |
+```bash |
|
| 426 |
+$ oc whoami -t |
|
| 427 |
+<token> |
|
| 258 | 428 |
``` |
| 429 |
+ |
|
| 430 |
+See also [`oc login`](#oc-login). |