kubectl apply --dry-运行 行为异常
kubectl apply --dry-run behaving weirdly
我遇到了 kubectl 和 --dry-运行 的奇怪行为。
为简化起见,假设我有以下 yaml 文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: nginx
name: nginx
spec:
replicas: 3
selector:
matchLabels:
run: nginx
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
containers:
- image: nginxsdf
imagePullPolicy: Always
name: nginx
修改例如图像或副本数:
kubectl apply -f Deployment.yaml -o yaml --dry-run
向我输出具有 OLD 规范的资源
kubectl apply -f Deployment.yaml -o yaml
向我输出具有 NEW 规格的资源
根据文档:
--dry-run=false: If true, only print the object that would be sent, without sending it.
然而,打印的对象是旧对象,而不是将要发送到 ApiServer 的对象
在 minikube、gke v1.10.0 上测试
同时我为它开了一个新的 gitHub issue:
我在 kubernetes 问题页面得到了以下答案:
When updating existing objects, kubectl apply doesn't send an entire object, just a patch. It is not exactly correct to print either the existing object or the new object in dry-run mode... the outcome of the merge is what should be printed.
For kubectl to be able to accurately reflect the result of the apply, it would need to have the server-side apply logic clientside, which is a non-goal.
Current efforts are directed at moving apply logic to the server. As part of that, the ability to dry-run server-side has been added. kubectl apply --server-dry-run
will do what you want, printing the result of the apply merge, without actually persisting it.
@apelisse we should probably update the flag help for apply and possibly print a warning when using --dry-run when updating an object via apply to document the limitations of --dry-run and direct people to use --server-dry-run
客户端最新版本使用:
kubectl apply -f Deployment.yaml --dry-run=server
我遇到了 kubectl 和 --dry-运行 的奇怪行为。
为简化起见,假设我有以下 yaml 文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: nginx
name: nginx
spec:
replicas: 3
selector:
matchLabels:
run: nginx
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
containers:
- image: nginxsdf
imagePullPolicy: Always
name: nginx
修改例如图像或副本数:
kubectl apply -f Deployment.yaml -o yaml --dry-run
向我输出具有 OLD 规范的资源kubectl apply -f Deployment.yaml -o yaml
向我输出具有 NEW 规格的资源
根据文档:
--dry-run=false: If true, only print the object that would be sent, without sending it.
然而,打印的对象是旧对象,而不是将要发送到 ApiServer 的对象
在 minikube、gke v1.10.0 上测试
同时我为它开了一个新的 gitHub issue:
我在 kubernetes 问题页面得到了以下答案:
When updating existing objects, kubectl apply doesn't send an entire object, just a patch. It is not exactly correct to print either the existing object or the new object in dry-run mode... the outcome of the merge is what should be printed.
For kubectl to be able to accurately reflect the result of the apply, it would need to have the server-side apply logic clientside, which is a non-goal.
Current efforts are directed at moving apply logic to the server. As part of that, the ability to dry-run server-side has been added.
kubectl apply --server-dry-run
will do what you want, printing the result of the apply merge, without actually persisting it.@apelisse we should probably update the flag help for apply and possibly print a warning when using --dry-run when updating an object via apply to document the limitations of --dry-run and direct people to use --server-dry-run
客户端最新版本使用:
kubectl apply -f Deployment.yaml --dry-run=server