You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -61,29 +61,29 @@ deployment.apps/my-nginx created
61
61
Resource creation isn't the only operation that `kubectl` can perform in bulk. It can also extract resource names from configuration files in order to perform other operations, in particular to delete the same resources you created:
For larger numbers of resources, you'll find it easier to specify the selector (label query) specified using `-l` or `--selector`, to filter resources by their labels:
76
76
77
77
```shell
78
-
$ kubectl delete deployment,services -l app=nginx
78
+
kubectl delete deployment,services -l app=nginx
79
79
deployment.apps "my-nginx" deleted
80
80
service "my-nginx-svc" deleted
81
81
```
82
82
83
83
Because `kubectl` outputs resource names in the same syntax it accepts, it's easy to chain operations using `$()` or `xargs`:
84
84
85
85
```shell
86
-
$ kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service)
86
+
kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service)
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:
109
109
110
110
```shell
111
-
$ kubectl create -f project/k8s/development
111
+
kubectl create -f project/k8s/development
112
112
error: you must provide one or more resources by argument or filename (.json|.yaml|.yml|stdin)
113
113
```
114
114
115
115
Instead, specify the `--recursive` or `-R` flag with the `--filename,-f` flag as such:
@@ -240,7 +240,7 @@ Sometimes existing pods and other resources need to be relabeled before creating
240
240
For example, if you want to label all your nginx pods as frontend tier, simply run:
241
241
242
242
```shell
243
-
$ kubectl label pods -l app=nginx tier=fe
243
+
kubectl label pods -l app=nginx tier=fe
244
244
pod/my-nginx-2035384211-j5fhi labeled
245
245
pod/my-nginx-2035384211-u2c7e labeled
246
246
pod/my-nginx-2035384211-u3t6x labeled
@@ -250,7 +250,7 @@ This first filters all pods with the label "app=nginx", and then labels them wit
250
250
To see the pods you just labeled, run:
251
251
252
252
```shell
253
-
$ kubectl get pods -l app=nginx -L tier
253
+
kubectl get pods -l app=nginx -L tier
254
254
NAME READY STATUS RESTARTS AGE TIER
255
255
my-nginx-2035384211-j5fhi 1/1 Running 0 23m fe
256
256
my-nginx-2035384211-u2c7e 1/1 Running 0 23m fe
@@ -266,8 +266,8 @@ For more information, please see [labels](/docs/concepts/overview/working-with-o
266
266
Sometimes you would want to attach annotations to resources. Annotations are arbitrary non-identifying metadata for retrieval by API clients such as tools, libraries, etc. This can be done with `kubectl annotate`. For example:
@@ -283,22 +283,22 @@ For more information, please see [annotations](/docs/concepts/overview/working-w
283
283
When load on your application grows or shrinks, it's easy to scale with `kubectl`. For instance, to decrease the number of nginx replicas from 3 to 1, do:
284
284
285
285
```shell
286
-
$ kubectl scale deployment/my-nginx --replicas=1
286
+
kubectl scale deployment/my-nginx --replicas=1
287
287
deployment.extensions/my-nginx scaled
288
288
```
289
289
290
290
Now you only have one pod managed by the deployment.
291
291
292
292
```shell
293
-
$ kubectl get pods -l app=nginx
293
+
kubectl get pods -l app=nginx
294
294
NAME READY STATUS RESTARTS AGE
295
295
my-nginx-2035384211-j5fhi 1/1 Running 0 30m
296
296
```
297
297
298
298
To have the system automatically choose the number of nginx replicas as needed, ranging from 1 to 3, do:
@@ -320,7 +320,7 @@ Then, you can use [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-co
320
320
This command will compare the version of the configuration that you're pushing with the previous version and apply the changes you've made, without overwriting any automated changes to properties you haven't specified.
@@ -339,16 +339,16 @@ To use apply, always create resource initially with either `kubectl apply` or `k
339
339
Alternatively, you may also update resources with `kubectl edit`:
340
340
341
341
```shell
342
-
$ kubectl edit deployment/my-nginx
342
+
kubectl edit deployment/my-nginx
343
343
```
344
344
345
345
This is equivalent to first `get` the resource, edit it in text editor, and then `apply` the resource with the updated version:
346
346
347
347
```shell
348
-
$ kubectl get deployment my-nginx -o yaml > /tmp/nginx.yaml
348
+
kubectl get deployment my-nginx -o yaml > /tmp/nginx.yaml
349
349
$ vi /tmp/nginx.yaml
350
350
# do some edit, and then save the file
351
-
$ kubectl apply -f /tmp/nginx.yaml
351
+
kubectl apply -f /tmp/nginx.yaml
352
352
deployment.apps/my-nginx configured
353
353
$ rm /tmp/nginx.yaml
354
354
```
@@ -370,7 +370,7 @@ and
370
370
In some cases, you may need to update resource fields that cannot be updated once initialized, or you may just want to make a recursive change immediately, such as to fix broken pods created by a Deployment. To change such fields, use `replace --force`, which deletes and re-creates the resource. In this case, you can simply modify your original configuration file:
@@ -385,14 +385,14 @@ you should read [how to use `kubectl rolling-update`](/docs/tasks/run-applicatio
385
385
Let's say you were running version 1.7.9 of nginx:
386
386
387
387
```shell
388
-
$ kubectl run my-nginx --image=nginx:1.7.9 --replicas=3
388
+
kubectl run my-nginx --image=nginx:1.7.9 --replicas=3
389
389
deployment.apps/my-nginx created
390
390
```
391
391
392
392
To update to version 1.9.1, simply change `.spec.template.spec.containers[0].image` from `nginx:1.7.9` to `nginx:1.9.1`, with the kubectl commands we learned above.
393
393
394
394
```shell
395
-
$ kubectl edit deployment/my-nginx
395
+
kubectl edit deployment/my-nginx
396
396
```
397
397
398
398
That's it! The Deployment will declaratively update the deployed nginx application progressively behind the scene. It ensures that only a certain number of old replicas may be down while they are being updated, and only a certain number of new replicas may be created above the desired number of pods. To learn more details about it, visit [Deployment page](/docs/concepts/workloads/controllers/deployment/).
You can check that the secret was created like this:
78
78
79
79
```shell
80
-
$ kubectl get secrets
80
+
kubectl get secrets
81
81
NAME TYPE DATA AGE
82
82
db-user-pass Opaque 2 51s
83
83
84
-
$ kubectl describe secrets/db-user-pass
84
+
kubectl describe secrets/db-user-pass
85
85
Name: db-user-pass
86
86
Namespace: default
87
87
Labels: <none>
@@ -139,7 +139,7 @@ data:
139
139
Now create the Secret using [`kubectl create`](/docs/reference/generated/kubectl/kubectl-commands#create):
140
140
141
141
```shell
142
-
$ kubectl create -f ./secret.yaml
142
+
kubectl create -f ./secret.yaml
143
143
secret "mysecret" created
144
144
```
145
145
@@ -250,7 +250,7 @@ the option `-w 0` to `base64` commands or the pipeline `base64 | tr -d '\n'` if
250
250
Secrets can be retrieved via the `kubectl get secret` command. For example, to retrieve the secret created in the previous section:
251
251
252
252
```shell
253
-
$ kubectl get secret mysecret -o yaml
253
+
kubectl get secret mysecret -o yaml
254
254
apiVersion: v1
255
255
data:
256
256
username: YWRtaW4=
@@ -569,7 +569,7 @@ invalid keys that were skipped. The example shows a pod which refers to the
569
569
default/mysecret that contains 2 invalid keys, 1badkey and 2alsobad.
570
570
571
571
```shell
572
-
$ kubectl get events
572
+
kubectl get events
573
573
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON
574
574
0s 0s 1 dapi-test-pod Pod Warning InvalidEnvironmentVariableNames kubelet, 127.0.0.1 Keys [1badkey, 2alsobad] from the EnvFrom secret default/mysecret were skipped since they are considered invalid environment variable names.
575
575
```
@@ -592,7 +592,7 @@ start until all the pod's volumes are mounted.
0 commit comments