I am facing a weird behaviour with kubectl and --dry-run.
To simplify let's say that I have the following yaml file:
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
Modifying for example the image or the number of replicas:
kubectl apply -f Deployment.yaml -o yaml --dry-run
outputs me the resource having the OLD specifications
kubectl apply -f Deployment.yaml -o yaml
outputs me the resource having NEW specifications
According to the documentation:
--dry-run=false: If true, only print the object that would be sent, without sending it.
However the object printed is the old one and not the one that will be sent to the ApiServer
Tested on minikube, gke v1.10.0
In the meanwhile I opened a new gitHub issue for it:
Construct a YAML file using the annotated service and relate it to the server. Modify the notes in the file and execute the command 'kubectl apply -f –dry-run = client'. The output shows server-side observations instead of modified annotations.
You can trigger the feature from kubectl by using kubectl apply --server-dry-run , which will decorate the request with the dryRun flag and return the object as it would have been applied, or an error if it would have failed.
The command set kubectl apply is used at a terminal's command-line window to create or modify Kubernetes resources defined in a manifest file. This is called a declarative usage. The state of the resource is declared in the manifest file, then kubectl apply is used to implement that state.
I got the following answer in the kubernetes issue page:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With