@@ -538,7 +538,7 @@ kubectl delete -f <文件名>
538
538
```
539
539
540
540
<!--
541
- ### Alternative: `kubectl apply -f <directory/> -prune -l your=label`
541
+ ### Alternative: `kubectl apply -f <directory/> -- prune -l your=label`
542
542
543
543
Only use this if you know what you are doing.
544
544
-->
@@ -547,7 +547,7 @@ Only use this if you know what you are doing.
547
547
只有在充分理解此命令背后含义的情况下才建议这样操作。
548
548
549
549
<!--
550
- `kubectl apply -prune` is in alpha, and backwards incompatible
550
+ `kubectl apply -- prune` is in alpha, and backwards incompatible
551
551
changes might be introduced in subsequent releases.
552
552
-->
553
553
{{< warning >}}
@@ -556,12 +556,16 @@ changes might be introduced in subsequent releases.
556
556
{{< /warning >}}
557
557
558
558
{{< warning >}}
559
+ <!--
560
+ You must be careful when using this command, so that you
561
+ do not delete objects unintentionally.
562
+ -->
559
563
在使用此命令时必须小心,这样才不会无意中删除不想删除的对象。
560
564
{{< /warning >}}
561
565
562
566
<!--
563
567
As an alternative to `kubectl delete`, you can use `kubectl apply` to identify objects to be deleted after their
564
- configuration files have been removed from the directory. Apply with `-prune`
568
+ configuration files have been removed from the directory. Apply with `-- prune`
565
569
queries the API server for all objects matching a set of labels, and attempts
566
570
to match the returned live object configurations against the object
567
571
configuration files. If an object matches the query, and it does not have a
@@ -575,6 +579,10 @@ it is deleted.
575
579
如果某对象在查询中被匹配到,但在目录中没有文件与其相对应,并且其中还包含
576
580
` last-applied-configuration ` 注解,则该对象会被删除。
577
581
582
+ {{< comment >}}
583
+ TODO(pwittrock): We need to change the behavior to prevent the user from running apply on subdirectories unintentionally.
584
+ {{< /comment >}}
585
+
578
586
``` shell
579
587
kubectl apply -f < directory/> --prune -l < labels>
580
588
```
@@ -679,6 +687,8 @@ kind: Deployment
679
687
metadata :
680
688
annotations :
681
689
# ...
690
+ # 注意注解中并不包含 replicas
691
+ # 这是因为更新并不是通过 kubectl apply 来执行的
682
692
kubectl.kubernetes.io/last-applied-configuration : |
683
693
{"apiVersion":"apps/v1","kind":"Deployment",
684
694
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
@@ -687,7 +697,7 @@ metadata:
687
697
"ports":[{"containerPort":80}]}]}}}}
688
698
# ...
689
699
spec :
690
- replicas : 2
700
+ replicas : 2 # written by scale
691
701
# ...
692
702
minReadySeconds : 5
693
703
selector :
@@ -753,7 +763,7 @@ kind: Deployment
753
763
metadata :
754
764
annotations :
755
765
# ...
756
- # 注解中包含更新后的 image,nginx 1.11.9 ,
766
+ # 注解中包含更新后的 image,nginx 1.16.1 ,
757
767
# 但不包含更新后的 replicas
758
768
kubectl.kubernetes.io/last-applied-configuration : |
759
769
{"apiVersion":"apps/v1","kind":"Deployment",
@@ -767,8 +777,8 @@ spec:
767
777
matchLabels :
768
778
# ...
769
779
app : nginx
770
- replicas : 2
771
- # minReadySeconds 此字段被清除
780
+ replicas : 2 # 由 `kubectl scale` 设置,被 `kubectl apply` 命令忽略
781
+ # minReadySeconds 此字段被`kubectl apply`清除
772
782
# ...
773
783
template :
774
784
metadata :
@@ -777,7 +787,7 @@ spec:
777
787
app : nginx
778
788
spec :
779
789
containers :
780
- - image : nginx:1.16.1
790
+ - image : nginx:1.16.1 # 由 `kubectl apply` 设置
781
791
# ...
782
792
name : nginx
783
793
ports :
@@ -1430,6 +1440,14 @@ It is OK to use imperative deletion with declarative management.
1430
1440
在声明式管理方法中使用指令式命令来删除对象是可以的。
1431
1441
{{< /note >}}
1432
1442
1443
+ {{< comment >}}
1444
+ TODO(pwittrock) : We need to make using imperative commands with
1445
+ declarative object configuration work so that it doesn't write the
1446
+ fields to the annotation, and instead. Then add this bullet point.
1447
+
1448
+ - using imperative commands with declarative configuration to manage where each manages different fields.
1449
+ {{< /comment >}}
1450
+
1433
1451
<!--
1434
1452
# ## Migrating from imperative command management to declarative object configuration
1435
1453
@@ -1446,52 +1464,51 @@ configuration involves several manual steps:
1446
1464
kubectl get <kind>/<name> -o yaml > <kind>_<name>.yaml
1447
1465
` ` `
1448
1466
1449
- 1 . Manually remove the `status` field from the configuration file.
1467
+ 2 . Manually remove the `status` field from the configuration file.
1450
1468
1451
1469
{{< note >}}
1452
- This step is optional, as `kubectl apply` does not update the status field
1453
- even if it is present in the configuration file.
1470
+ This step is optional, as `kubectl apply` does not update the status field even if it is present in the configuration file.
1454
1471
{{< /note >}}
1455
1472
1456
- 1 . Set the `kubectl.kubernetes.io/last-applied-configuration` annotation on the object :
1473
+ 3 . Set the `kubectl.kubernetes.io/last-applied-configuration` annotation on the object :
1457
1474
1458
1475
` ` ` shell
1459
- kubectl replace -save-config -f <kind>_<name>.yaml
1476
+ kubectl replace -- save-config -f <kind>_<name>.yaml
1460
1477
` ` `
1461
1478
1462
- 1 . Change processes to use `kubectl apply` for managing the object exclusively.
1479
+ 4 . Change processes to use `kubectl apply` for managing the object exclusively.
1463
1480
-->
1464
1481
1. 将现时对象导出到本地配置文件:
1465
1482
1466
1483
` ` ` shell
1467
1484
kubectl get <kind>/<name> -o yaml > <kind>_<name>.yaml
1468
1485
` ` `
1469
1486
1470
- 1 . 手动移除配置文件中的 `status` 字段。
1487
+ 2 . 手动移除配置文件中的 `status` 字段。
1471
1488
1472
- <!--
1473
- This step is optional, as `kubectl apply` does not update the status field
1474
- even if it is present in the configuration file.
1475
- -->
1476
1489
{{< note >}}
1477
1490
这一步骤是可选的,因为 `kubectl apply` 并不会更新 status 字段,即便
1478
1491
配置文件中包含 status 字段。
1479
1492
{{< /note >}}
1480
1493
1481
- 1 . 设置对象上的 `kubectl.kubernetes.io/last-applied-configuration` 注解:
1494
+ 3 . 设置对象上的 `kubectl.kubernetes.io/last-applied-configuration` 注解:
1482
1495
1483
1496
` ` ` shell
1484
1497
kubectl replace --save-config -f <kind>_<name>.yaml
1485
1498
` ` `
1486
- 1. 更改过程,使用 `kubectl apply` 专门管理对象。
1499
+ 4. 更改过程,使用 `kubectl apply` 专门管理对象。
1500
+
1501
+ {{< comment >}}
1502
+ TODO(pwittrock) : Why doesn't export remove the status field? Seems like it should.
1503
+ {{< /comment >}}
1487
1504
1488
1505
<!--
1489
1506
# ## Migrating from imperative object configuration to declarative object configuration
1490
1507
1491
1508
1. Set the `kubectl.kubernetes.io/last-applied-configuration` annotation on the object :
1492
1509
1493
1510
` ` ` shell
1494
- kubectl replace -save-config -f <kind>_<name>.yaml
1511
+ kubectl replace -- save-config -f <kind>_<name>.yaml
1495
1512
` ` `
1496
1513
1497
1514
1. Change processes to use `kubectl apply` for managing the object exclusively.
@@ -1501,7 +1518,7 @@ configuration involves several manual steps:
1501
1518
1. 在对象上设置 `kubectl.kubernetes.io/last-applied-configuration` 注解:
1502
1519
1503
1520
` ` ` shell
1504
- kubectl replace -save-config -f <kind>_<name>.yaml
1521
+ kubectl replace -- save-config -f <kind>_<name>.yaml
1505
1522
` ` `
1506
1523
1507
1524
1. 自此排他性地使用 `kubectl apply` 来管理对象。
0 commit comments