I am trying to update a deployment via the YAML file, similar to this question. I have the following yaml file...
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-server-deployment
labels:
app: simple-server
spec:
replicas: 3
selector:
matchLabels:
app: simple-server
template:
metadata:
labels:
app: simple-server
spec:
containers:
- name: simple-server
image: nginx
ports:
- name: http
containerPort: 80
I tried changing the code by changing replicas: 3
to replicas: 1
. Next I redeployed like kubectl apply -f simple-deployment.yml
and I get deployment.apps/simple-server-deployment configured
. However, when I run kubectl rollout history deployment/simple-server-deployment
I only see 1 entry...
REVISION CHANGE-CAUSE
1 <none>
How do I do the same thing while increasing the revision so it is possible to rollback?
I know this can be done without the YAML but this is just an example case. In the real world I will have far more changes and need to use the YAML.
CodePudding user response:
Change of replicas does not create new history record. You can add --record
to you apply
command and check the annotation later to see what was the last spec applied.
CodePudding user response:
You can use --record
flag so in your case the command will look like:
kubectl apply -f simple-deployment.yml --record
However, a few notes.
First, --record
flag is deprecated - you will see following message when you will run kubectl apply
with the --record
flag:
Flag --record has been deprecated, --record will be removed in the future
However, there is no replacement for this flag yet, but keep in mind that in the future there probably will be.
Second thing, not every change will be recorded (even with --record
flag) - I tested your example from the main question and there is no new revision. Why? It's because::
@deech this is expected behavior. The
Deployment
only create a new revision (i.e. anotherReplica Set
) when you update its pod template. Scaling it won't create another revision.
Considering the two above, you need to think (and probably test) if the --record
flag is suitable for you. Maybe it's better to use some version control system like git, but as I said, it depends on your requirements.
CodePudding user response:
To accomplish this, use GitOps approach for CD.
GitOps is a method used to manage Kubernetes clusters and deliver applications more efficiently. It uses Git as the only trusted source of declarative infrastructure and applications for Kubernetes clusters.
With git revert you can exactly do what you want in your post.
Further reading: