[英]Kubectl patch is not updating the apiVersion correctly
I run kubent
and identify an outdated apiVersion我运行
kubent
并确定了一个过时的 apiVersion
> kubent
...
KIND NAMESPACE NAME API_VERSION REPLACE_WITH (SINCE)
PodDisruptionBudget mynamespace mypdb policy/v1beta1 policy/v1 (1.21.0)
I try to patch the resource in place but that doesn't seem to work:我尝试修补资源,但这似乎不起作用:
kubectl patch PodDisruptionBudget mypdb --namespace mynamespace -p'{"apiVersion":"policy/v1"}'
poddisruptionbudget.policy/mypdb patched (no change)
Running kubent
still shows its outdated.运行
kubent
仍然显示它已经过时。
Why doesn't patch work for updating apiVersion?为什么补丁不能用于更新 apiVersion? I need to do this for many resources in many namespaces I want to script it out.
我需要为许多命名空间中的许多资源执行此操作,我想将其编写成脚本。
Also, when I run kubectl edit PodDisruptionBudget mypdb --namespace mynamespace
it shows the apiVersion is the updated one ("policy/v1"), but kubent
still shows it as outdated (policy/v1beta1).此外,当我运行
kubectl edit PodDisruptionBudget mypdb --namespace mynamespace
时,它显示 apiVersion 是更新的版本(“policy/v1”),但kubent
仍然显示它已过时(policy/v1beta1)。
Here is a solution for you.这是为您提供的解决方案。
kubent
### output:
(⎈ |minikube:default)[23:23:23] [~/repositories/KubernetesLabs] git(master) 🔥 ❱❱❱ kubent
11:23PM INF >>> Kube No Trouble `kubent` <<<
11:23PM INF version 0.5.1 (git sha a762ff3c6b5622650b86dc982652843cc2bd123c)
11:23PM INF Initializing collectors and retrieving data
11:23PM INF Target K8s version is 1.23.3
11:23PM INF Retrieved 52 resources from collector name=Cluster
11:23PM INF Retrieved 0 resources from collector name="Helm v2"
11:23PM INF Retrieved 9 resources from collector name="Helm v3"
11:23PM INF Loaded ruleset name=custom.rego.tmpl
11:23PM INF Loaded ruleset name=deprecated-1-16.rego
11:23PM INF Loaded ruleset name=deprecated-1-22.rego
11:23PM INF Loaded ruleset name=deprecated-1-25.rego
__________________________________________________________________________________________
>>> Deprecated APIs removed in 1.25 <<<
------------------------------------------------------------------------------------------
KIND NAMESPACE NAME API_VERSION REPLACE_WITH (SINCE)
PodDisruptionBudget istio-system istio-ingressgateway policy/v1beta1 policy/v1 (1.21.0)
PodDisruptionBudget istio-system istiod policy/v1beta1 policy/v1 (1.21.0)
apiVersion
and will display the correct one.apiVersion
并显示正确的版本。# Get the list of outdated resources in a json format
kubent -o json > outdated.json
# Check the output
cat outdated.json
# Grab the desired resource name(s) from the json and loop over them ==> script
# The content of your script will be
# (loop over the list and run the following command):
- Get the updated API using kubectl get
- Save the updated content to file
- apply the changes
kubectl get <resourceType> \
<resourceName> \
-n <namespace> \
-o yaml > newUpdatedApi.yaml \
&& kubectl apply -f newUpdatedApi.yaml
# Print out the outdated resources
kubent
# Get the updated apiVersion and save to file
# also apply the changes
kubectl get PodDisruptionBudget \
istiod \
-n istio-system \
-o yaml > updated.yaml \
&& kubectl apply -f updated.yaml
# Check to verify that the updated.yaml indeed have the desired apiVersion
head -1 updated.yaml
# Verify that the "patch" is made
kubent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.