@@ -585,12 +585,12 @@ And you can see the `retainKeys` strategy in the
585
585
` retainKey ` 策略。
586
586
587
587
<!--
588
- ## Alternate forms of the kubectl patch command
588
+ ### Alternate forms of the kubectl patch command
589
589
590
590
The `kubectl patch` command takes YAML or JSON. It can take the patch as a file or
591
591
directly on the command line.
592
592
-->
593
- ## kubectl patch 命令的其他形式 {#alternate-forms-of-the-kubectl-patch-command}
593
+ ### kubectl patch 命令的其他形式 {#alternate-forms-of-the-kubectl-patch-command}
594
594
595
595
` kubectl patch ` 命令使用 YAML 或 JSON。它可以接受以文件形式提供的补丁,也可以接受直接在命令行中给出的补丁。
596
596
@@ -628,6 +628,128 @@ kubectl patch deployment patch-demo --patch 'spec:\n template:\n spec:\n cont
628
628
kubectl patch deployment patch-demo --patch-file patch-file.json
629
629
kubectl patch deployment patch-demo --patch ' {"spec": {"template": {"spec": {"containers": [{"name": "patch-demo-ctr-2","image": "redis"}]}}}}'
630
630
```
631
+ <!--
632
+ ### Update an object's replica count using `kubectl patch` with `--subresource` {#scale-kubectl-patch}
633
+ -->
634
+ ### 使用 ` kubectl patch ` 和 ` --subresource ` 更新一个对象的副本数 {#scale-kubectl-patch}
635
+
636
+ {{< feature-state for_k8s_version="v1.24" state="alpha" >}}
637
+
638
+ <!--
639
+ The flag `--subresource=[subresource-name]` is used with kubectl commands like get, patch,
640
+ edit and replace to fetch and update `status` and `scale` subresources of the resources
641
+ (applicable for kubectl version v1.24 or more). This flag is used with all the API resources
642
+ (built-in and CRs) which has `status` or `scale` subresource. Deployment is one of the
643
+ examples which supports these subresources.
644
+
645
+ Here's a manifest for a Deployment that has two replicas:
646
+ -->
647
+ 使用 kubectl 命令(如 get、patch、edit 和 replace)时带上 ` --subresource=[subresource-name] ` 标志,
648
+ 可以获取和更新资源的 ` status ` 和 ` scale ` 子资源(适用于 kubectl v1.24 或更高版本)。
649
+ 这个标志可用于带有 ` status ` 或 ` scale ` 子资源的所有 API 资源 (内置资源和 CR 资源)。
650
+ Deployment 是支持这些子资源的其中一个例子。
651
+
652
+ 下面是有两个副本的 Deployment 的清单。
653
+
654
+ {{< codenew file="application/deployment.yaml" >}}
655
+
656
+ <!--
657
+ Create the Deployment:
658
+ -->
659
+ 创建 Deployment:
660
+
661
+ ``` shell
662
+ kubectl apply -f https://k8s.io/examples/application/deployment.yaml
663
+ ```
664
+
665
+ <!--
666
+ View the Pods associated with your Deployment:
667
+ -->
668
+ 查看与 Deployment 关联的 Pod:
669
+
670
+ ``` shell
671
+ kubectl get pods -l app=nginx
672
+ ```
673
+
674
+ <!--
675
+ In the output, you can see that Deployment has two Pods. For example:
676
+ -->
677
+ 在输出中,你可以看到此 Deployment 有两个 Pod。例如:
678
+
679
+ ```
680
+ NAME READY STATUS RESTARTS AGE
681
+ nginx-deployment-7fb96c846b-22567 1/1 Running 0 47s
682
+ nginx-deployment-7fb96c846b-mlgns 1/1 Running 0 47s
683
+ ```
684
+
685
+ <!--
686
+ Now, patch that Deployment with `--subresource=[subresource-name]` flag:
687
+ -->
688
+ 现在用 ` --subresource=[subresource-name] ` 标志修补此 Deployment:
689
+
690
+ ``` shell
691
+ kubectl patch deployment nginx-deployment --subresource=' scale' --type=' merge' -p ' {"spec":{"replicas":3}}'
692
+ ```
693
+
694
+ <!--
695
+ The output is:
696
+ -->
697
+ 输出为:
698
+
699
+ ``` shell
700
+ scale.autoscaling/nginx-deployment patched
701
+ ```
702
+
703
+ <!--
704
+ View the Pods associated with your patched Deployment:
705
+ -->
706
+ 查看与你所修补的 Deployment 关联的 Pod:
707
+
708
+ ``` shell
709
+ kubectl get pods -l app=nginx
710
+ ```
711
+
712
+ <!--
713
+ In the output, you can see one new pod is created, so now you have 3 running pods.
714
+ -->
715
+ 在输出中,你可以看到一个新的 Pod 被创建,因此现在你有 3 个正在运行的 Pod。
716
+
717
+ ```
718
+ NAME READY STATUS RESTARTS AGE
719
+ nginx-deployment-7fb96c846b-22567 1/1 Running 0 107s
720
+ nginx-deployment-7fb96c846b-lxfr2 1/1 Running 0 14s
721
+ nginx-deployment-7fb96c846b-mlgns 1/1 Running 0 107s
722
+ ```
723
+
724
+ <!--
725
+ View the patched Deployment:
726
+ -->
727
+ 查看所修补的 Deployment:
728
+
729
+ ``` shell
730
+ kubectl get deployment nginx-deployment -o yaml
731
+ ```
732
+
733
+ ``` yaml
734
+ ...
735
+ spec :
736
+ replicas : 3
737
+ ...
738
+ status :
739
+ ...
740
+ availableReplicas : 3
741
+ readyReplicas : 3
742
+ replicas : 3
743
+ ` ` `
744
+
745
+ {{< note >}}
746
+ <!--
747
+ If you run ` kubectl patch` and specify `--subresource` flag for resource that doesn't support that
748
+ particular subresource, the API server returns a 404 Not Found error.
749
+ -->
750
+ 如果你运行 `kubectl patch` 并指定 `--subresource` 标志时,所针对的是不支持特定子资源的资源,
751
+ 则 API 服务器会返回一个 404 Not Found 错误。
752
+ {{< /note >}}
631
753
632
754
<!--
633
755
# # Summary
0 commit comments