Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of --record in kubectl imperative commands in Kubernetes

I tried to find useful information when should i use --record. I created 3 commands:

  • k set image deployment web1 nginx=lfccncf/nginx:latest --record
  • k rollout undo deployment/web1 --record
  • k -n kdpd00202 edit deployment web1 --record

Could anyone tell me if I need to use --record in each of these 3 commands?

When is it necessary to use --record and when is it useless?

like image 674
O.Man Avatar asked Jul 10 '20 09:07

O.Man


People also ask

What is -- record in Kubernetes?

You can specify the --record flag to write the command executed in the resource annotation kubernetes.io/change-cause . The recorded change is useful for future introspection. For example, to see the commands executed in each Deployment revision.

What are imperative commands in Kubernetes?

Imperative commands are used to create, update and delete objects on Kubernetes clusters without having to specify any manifest files beforehand. They are a godsend for Kubernetes application developers and administrators because they are very easy to remember and let you get things done more efficiently!

What provides a record of intent for the Kubernetes API?

A Kubernetes object is a "record of intent"--once you create the object, the Kubernetes system will constantly work to ensure that object exists. By creating an object, you're effectively telling the Kubernetes system what you want your cluster's workload to look like; this is your cluster's desired state.

What is kubectl in Kubernetes?

It is one of the key components of Kubernetes which runs on the workstation on any machine when the setup is done. It has the capability to manage the nodes in the cluster. Kubectl commands are used to interact and manage Kubernetes objects and the cluster. In this chapter, we will discuss a few commands used in Kubernetes via kubectl.

What is an imperative command in Kubernetes?

This is a method commonly used in CICD pipelines where YAMLs usually present. Imperative commands are used to create, update and delete objects on Kubernetes clusters without having to specify any manifest files beforehand.

What is Kubernetes command line interface?

Kubectl stands for “Kubernetes Command-line interface”. It is a command-line tool for the Kubernetes platform to perform API calls. Kubectl is the main interface that allows users to create (and manage) individual objects or groups of objects inside a Kubernetes cluster. As a user, Kubectl helps you to control Kubernetes as a cockpit.

What is the use of kubectl rollout and Run command?

kubectl rollout − It is capable of managing the rollout of deployment. kubectl run − Run command has the capability to run an image on the Kubernetes cluster. kubectl scale − It will scale the size of Kubernetes Deployments, ReplicaSet, Replication Controller, or job.


1 Answers

You can specify the --record flag to write the command executed in the resource annotation kubernetes.io/change-cause. The recorded change is useful for future introspection. For example, to see the commands executed in each Deployment revision.

kubectl rollout history deployment.v1.apps/nginx-deployment
The output is similar to this:

deployments "nginx-deployment"
REVISION    CHANGE-CAUSE
1           kubectl apply --filename=https://k8s.io/examples/controllers/nginx-deployment.yaml --record=true
2           kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.16.1 --record=true
3           kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.161 --record=true

So it's not mandatory for any of the commands and but is recommended for kubectl set image because you will not see anything in CHANGE-CAUSE section as above if you skip --record

like image 52
Arghya Sadhu Avatar answered Oct 12 '22 15:10

Arghya Sadhu