Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update kubectl documentation #12867

Merged
merged 5 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/en/docs/concepts/cluster-administration/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a container that writes some text to standard output once per second.
To run this pod, use the following command:

```shell
$ kubectl create -f https://k8s.io/examples/debug/counter-pod.yaml
$ kubectl apply -f https://k8s.io/examples/debug/counter-pod.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

pod/counter created
Liujingfang1 marked this conversation as resolved.
Show resolved Hide resolved
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ Many applications require multiple resources to be created, such as a Deployment
Multiple resources can be created the same way as a single resource:

```shell
$ kubectl create -f https://k8s.io/examples/application/nginx-app.yaml
$ kubectl apply -f https://k8s.io/examples/application/nginx-app.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

service/my-nginx-svc created
deployment.apps/my-nginx created
```

The resources will be created in the order they appear in the file. Therefore, it's best to specify the service first, since that will ensure the scheduler can spread the pods associated with the service as they are created by the controller(s), such as Deployment.

`kubectl create` also accepts multiple `-f` arguments:
`kubectl apply` also accepts multiple `-f` arguments:

```shell
$ kubectl create -f https://k8s.io/examples/application/nginx/nginx-svc.yaml -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml
$ kubectl apply -f https://k8s.io/examples/application/nginx/nginx-svc.yaml -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

```

And a directory can be specified rather than or in addition to individual files:

```shell
$ kubectl create -f https://k8s.io/examples/application/nginx/
$ kubectl apply -f https://k8s.io/examples/application/nginx/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

```

`kubectl` will read any files with suffixes `.yaml`, `.yml`, or `.json`.
Expand All @@ -52,7 +52,7 @@ It is a recommended practice to put resources related to the same microservice o
A URL can also be specified as a configuration source, which is handy for deploying directly from configuration files checked into github:

```shell
$ kubectl create -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/nginx/nginx-deployment.yaml
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/nginx/nginx-deployment.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

deployment.apps/my-nginx created
```

Expand Down Expand Up @@ -83,7 +83,7 @@ service "my-nginx-svc" deleted
Because `kubectl` outputs resource names in the same syntax it accepts, it's easy to chain operations using `$()` or `xargs`:

```shell
$ kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service)
$ kubectl get $(kubectl apply -f docs/concepts/cluster-administration/nginx/ -o name | grep service)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx-svc LoadBalancer 10.0.0.208 <pending> 80/TCP 0s
```
Expand All @@ -108,14 +108,14 @@ project/k8s/development
By default, performing a bulk operation on `project/k8s/development` will stop at the first level of the directory, not processing any subdirectories. If we had tried to create the resources in this directory using the following command, we would have encountered an error:

```shell
$ kubectl create -f project/k8s/development
$ kubectl apply -f project/k8s/development
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

error: you must provide one or more resources by argument or filename (.json|.yaml|.yml|stdin)
```

Instead, specify the `--recursive` or `-R` flag with the `--filename,-f` flag as such:

```shell
$ kubectl create -f project/k8s/development --recursive
$ kubectl apply -f project/k8s/development --recursive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove $ to align on style guideline and be consistent

configmap/my-config created
deployment.apps/my-deployment created
persistentvolumeclaim/my-pvc created
Expand All @@ -126,7 +126,7 @@ The `--recursive` flag works with any operation that accepts the `--filename,-f`
The `--recursive` flag also works when multiple `-f` arguments are provided:

```shell
$ kubectl create -f project/k8s/namespaces -f project/k8s/development --recursive
$ kubectl apply -f project/k8s/namespaces -f project/k8s/development --recursive
namespace/development created
namespace/staging created
configmap/my-config created
Expand Down Expand Up @@ -169,7 +169,7 @@ and
The labels allow us to slice and dice our resources along any dimension specified by a label:

```shell
$ kubectl create -f examples/guestbook/all-in-one/guestbook-all-in-one.yaml
$ kubectl apply -f examples/guestbook/all-in-one/guestbook-all-in-one.yaml
$ kubectl get pods -Lapp -Ltier -Lrole
NAME READY STATUS RESTARTS AGE APP TIER ROLE
guestbook-fe-4nlpb 1/1 Running 0 1m guestbook frontend <none>
Expand Down Expand Up @@ -331,7 +331,7 @@ Currently, resources are created without this annotation, so the first invocatio
All subsequent calls to `kubectl apply`, and other commands that modify the configuration, such as `kubectl replace` and `kubectl edit`, will update the annotation, allowing subsequent calls to `kubectl apply` to detect and perform deletions using a three-way diff.

{{< note >}}
To use apply, always create resource initially with either `kubectl apply` or `kubectl create --save-config`.
To use apply, always create resource initially with either `kubectl apply`.
{{< /note >}}
Liujingfang1 marked this conversation as resolved.
Show resolved Hide resolved

### kubectl edit
Expand Down Expand Up @@ -379,8 +379,7 @@ deployment.apps/my-nginx replaced

At some point, you'll eventually need to update your deployed application, typically by specifying a new image or image tag, as in the canary deployment scenario above. `kubectl` supports several update operations, each of which is applicable to different scenarios.

We'll guide you through how to create and update applications with Deployments. If your deployed application is managed by Replication Controllers,
you should read [how to use `kubectl rolling-update`](/docs/tasks/run-application/rolling-update-replication-controller/) instead.
We'll guide you through how to create and update applications with Deployments.

Let's say you were running version 1.7.9 of nginx:

Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/concepts/configuration/assign-pod-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Then add a nodeSelector like so:

{{< codenew file="pods/pod-nginx.yaml" >}}

When you then run `kubectl create -f https://k8s.io/examples/pods/pod-nginx.yaml`,
When you then run `kubectl apply -f https://k8s.io/examples/pods/pod-nginx.yaml`,
the Pod will get scheduled on the node that you attached the label to. You can
verify that it worked by running `kubectl get pods -o wide` and looking at the
"NODE" that the Pod was assigned to.
Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/concepts/configuration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is a living document. If you think of something that is not on this list bu

- Group related objects into a single file whenever it makes sense. One file is often easier to manage than several. See the [guestbook-all-in-one.yaml](https://github.com/kubernetes/examples/tree/{{< param "githubbranch" >}}/guestbook/all-in-one/guestbook-all-in-one.yaml) file as an example of this syntax.

- Note also that many `kubectl` commands can be called on a directory. For example, you can call `kubectl create` on a directory of config files.
- Note also that many `kubectl` commands can be called on a directory. For example, you can call `kubectl apply` on a directory of config files.

- Don't specify default values unnecessarily: simple, minimal configuration will make errors less likely.

Expand Down Expand Up @@ -97,7 +97,7 @@ The caching semantics of the underlying image provider make even `imagePullPolic

## Using kubectl

- Use `kubectl apply -f <directory>` or `kubectl create -f <directory>`. This looks for Kubernetes configuration in all `.yaml`, `.yml`, and `.json` files in `<directory>` and passes it to `apply` or `create`.
- Use `kubectl apply -f <directory>`. This looks for Kubernetes configuration in all `.yaml`, `.yml`, and `.json` files in `<directory>` and passes it to `apply`.

- Use label selectors for `get` and `delete` operations instead of specific object names. See the sections on [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors) and [using labels effectively](/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Here's an example `.yaml` file that shows the required fields and object spec fo
{{< codenew file="application/deployment.yaml" >}}

One way to create a Deployment using a `.yaml` file like the one above is to use the
[`kubectl create`](/docs/reference/generated/kubectl/kubectl-commands#create) command
[`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply) command
in the `kubectl` command-line interface, passing the `.yaml` file as an argument. Here's an example:

```shell
$ kubectl create -f https://k8s.io/examples/application/deployment.yaml --record
$ kubectl apply -f https://k8s.io/examples/application/deployment.yaml --record
```

The output is similar to this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Create an nginx Pod, and note that it has a container port specification:
This makes it accessible from any node in your cluster. Check the nodes the Pod is running on:

```shell
$ kubectl create -f ./run-my-nginx.yaml
$ kubectl apply -f ./run-my-nginx.yaml
$ kubectl get pods -l run=my-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE
my-nginx-3800858182-jr4a2 1/1 Running 0 13s 10.244.3.4 kubernetes-minion-905m
Expand Down Expand Up @@ -67,7 +67,7 @@ $ kubectl expose deployment/my-nginx
service/my-nginx exposed
```

This is equivalent to `kubectl create -f` the following yaml:
This is equivalent to `kubectl apply -f` the following yaml:

{{< codenew file="service/networking/nginx-svc.yaml" >}}

Expand Down Expand Up @@ -211,7 +211,7 @@ You can acquire all these from the [nginx https example](https://github.com/kube

```shell
$ make keys secret KEY=/tmp/nginx.key CERT=/tmp/nginx.crt SECRET=/tmp/secret.json
$ kubectl create -f /tmp/secret.json
$ kubectl apply -f /tmp/secret.json
secret/nginxsecret created
$ kubectl get secrets
NAME TYPE DATA AGE
Expand Down Expand Up @@ -242,7 +242,7 @@ data:
Now create the secrets using the file:

```shell
$ kubectl create -f nginxsecrets.yaml
$ kubectl apply -f nginxsecrets.yaml
$ kubectl get secrets
NAME TYPE DATA AGE
default-token-il9rc kubernetes.io/service-account-token 1 1d
Expand All @@ -263,7 +263,7 @@ Noteworthy points about the nginx-secure-app manifest:
This is setup *before* the nginx server is started.

```shell
$ kubectl delete deployments,svc my-nginx; kubectl create -f ./nginx-secure-app.yaml
$ kubectl delete deployments,svc my-nginx; kubectl apply -f ./nginx-secure-app.yaml
```

At this point you can reach the nginx server from any node.
Expand All @@ -283,7 +283,7 @@ Let's test this from a pod (the same secret is being reused for simplicity, the
{{< codenew file="service/networking/curlpod.yaml" >}}

```shell
$ kubectl create -f ./curlpod.yaml
$ kubectl apply -f ./curlpod.yaml
$ kubectl get pods -l app=curlpod
NAME READY STATUS RESTARTS AGE
curl-deployment-1515033274-1410r 1/1 Running 0 1m
Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/concepts/services-networking/ingress.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ There are existing Kubernetes concepts that allow you to expose a single Service

{{< codenew file="service/networking/ingress.yaml" >}}

If you create it using `kubectl create -f` you should see:
If you create it using `kubectl apply -f` you should see:

```shell
kubectl get ingress test-ingress
Expand Down Expand Up @@ -224,7 +224,7 @@ spec:
servicePort: 8080
```

When you create the ingress with `kubectl create -f`:
When you create the ingress with `kubectl apply -f`:

```shell
kubectl describe ingress simple-fanout-example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ You can describe a DaemonSet in a YAML file. For example, the `daemonset.yaml` f

* Create a DaemonSet based on the YAML file:
```
kubectl create -f https://k8s.io/examples/controllers/daemonset.yaml
kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml
```

### Required Fields
Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/concepts/workloads/controllers/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ In this example:
To create this Deployment, run the following command:

```shell
kubectl create -f https://k8s.io/examples/controllers/nginx-deployment.yaml
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
```

{{< note >}}
Expand Down Expand Up @@ -429,7 +429,7 @@ First, check the revisions of this deployment:
$ kubectl rollout history deployment.v1.apps/nginx-deployment
deployments "nginx-deployment"
REVISION CHANGE-CAUSE
1 kubectl create --filename=https://k8s.io/examples/controllers/nginx-deployment.yaml --record=true
1 kubectl apply --filename=https://k8s.io/examples/controllers/nginx-deployment.yaml --record=true
2 kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 --record=true
3 kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.91 --record=true
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you create the ReplicaSet and then view the Pod metadata, you can see
OwnerReferences field:

```shell
kubectl create -f https://k8s.io/examples/controllers/replicaset.yaml
kubectl apply -f https://k8s.io/examples/controllers/replicaset.yaml
kubectl get pods --output=yaml
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ It takes around 10s to complete.
Run the example job by downloading the example file and then running this command:

```shell
$ kubectl create -f https://k8s.io/examples/controllers/job.yaml
$ kubectl apply -f https://k8s.io/examples/controllers/job.yaml
job "pi" created
```

Expand Down
10 changes: 5 additions & 5 deletions content/en/docs/concepts/workloads/controllers/replicaset.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Saving this manifest into `frontend.yaml` and submitting it to a Kubernetes clus
create the defined ReplicaSet and the Pods that it manages.

```shell
kubectl create -f http://k8s.io/examples/controllers/frontend.yaml
kubectl apply -f http://k8s.io/examples/controllers/frontend.yaml
```

You can then get the current ReplicaSets deployed:
Expand Down Expand Up @@ -162,7 +162,7 @@ Suppose you create the Pods after the frontend ReplicaSet has been deployed and
fulfill its replica count requirement:

```shell
kubectl create -f http://k8s.io/examples/pods/pod-rs.yaml
kubectl apply -f http://k8s.io/examples/pods/pod-rs.yaml
```

The new Pods will be acquired by the ReplicaSet, and then immediately terminated as the ReplicaSet would be over
Expand All @@ -184,12 +184,12 @@ pod2 0/1 Terminating 0 4s

If you create the Pods first:
```shell
kubectl create -f http://k8s.io/examples/pods/pod-rs.yaml
kubectl apply -f http://k8s.io/examples/pods/pod-rs.yaml
```

And then create the ReplicaSet however:
```shell
kubectl create -f http://k8s.io/examples/controllers/frontend.yaml
kubectl apply -f http://k8s.io/examples/controllers/frontend.yaml
```

You shall see that the ReplicaSet has acquired the Pods and has only created new ones according to its spec until the
Expand Down Expand Up @@ -304,7 +304,7 @@ create the defined HPA that autoscales the target ReplicaSet depending on the CP
of the replicated Pods.

```shell
kubectl create -f https://k8s.io/examples/controllers/hpa-rs.yaml
kubectl apply -f https://k8s.io/examples/controllers/hpa-rs.yaml
```

Alternatively, you can use the `kubectl autoscale` command to accomplish the same
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This example ReplicationController config runs three copies of the nginx web ser
Run the example job by downloading the example file and then running this command:

```shell
$ kubectl create -f https://k8s.io/examples/controllers/replication.yaml
$ kubectl apply -f https://k8s.io/examples/controllers/replication.yaml
replicationcontroller/nginx created
```

Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/concepts/workloads/pods/init-containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ spec:
This Pod can be started and debugged with the following commands:

```shell
$ kubectl create -f myapp.yaml
$ kubectl apply -f myapp.yaml
pod/myapp-pod created
$ kubectl get -f myapp.yaml
NAME READY STATUS RESTARTS AGE
Expand Down Expand Up @@ -226,7 +226,7 @@ Once we start the `mydb` and `myservice` services, we can see the Init Container
complete and the `myapp-pod` is created:

```shell
$ kubectl create -f services.yaml
$ kubectl apply -f services.yaml
service/myservice created
service/mydb created
$ kubectl get -f myapp.yaml
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/reference/access-authn-authz/rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To enable RBAC, start the apiserver with `--authorization-mode=RBAC`.
The RBAC API declares four top-level types which will be covered in this
section. Users can interact with these resources as they would with any other
API resource (via `kubectl`, API calls, etc.). For instance,
`kubectl create -f (resource).yml` can be used with any of these examples,
`kubectl apply -f (resource).yml` can be used with any of these examples,
though readers who wish to follow along should review the section on
bootstrapping first.

Expand Down
12 changes: 6 additions & 6 deletions content/en/docs/reference/kubectl/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ Kubernetes manifests can be defined in json or yaml. The file extension `.yaml`,
`.yml`, and `.json` can be used.

```bash
kubectl create -f ./my-manifest.yaml # create resource(s)
kubectl create -f ./my1.yaml -f ./my2.yaml # create from multiple files
kubectl create -f ./dir # create resource(s) in all manifest files in dir
kubectl create -f https://git.io/vPieo # create resource(s) from url
kubectl apply -f ./my-manifest.yaml # create resource(s)
kubectl apply -f ./my1.yaml -f ./my2.yaml # create from multiple files
kubectl apply -f ./dir # create resource(s) in all manifest files in dir
kubectl apply -f https://git.io/vPieo # create resource(s) from url
kubectl create deployment nginx --image=nginx # start a single instance of nginx
kubectl explain pods,svc # get the documentation for pod and svc manifests

# Create multiple YAML objects from stdin
cat <<EOF | kubectl create -f -
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -103,7 +103,7 @@ spec:
EOF

# Create a secret with several keys
cat <<EOF | kubectl create -f -
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/reference/kubectl/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ flag, which provides the object to be submitted to the cluster.

### `kubectl apply`

* You can use `kubectl apply` to create or update resources. However, to update a resource you should have created the resource by using `kubectl apply` or `kubectl create --save-config`. For more information about using kubectl apply to update resources, see [Managing Resources](/docs/concepts/cluster-administration/manage-deployment/#kubectl-apply).
* You can use `kubectl apply` to create or update resources. However, to update a resource you should have created the resource by using `kubectl apply`. For more information about using kubectl apply to update resources, see [Managing Resources](/docs/concepts/cluster-administration/manage-deployment/#kubectl-apply).
Liujingfang1 marked this conversation as resolved.
Show resolved Hide resolved

{{% /capture %}}
Loading