Sunday, December 13, 2020

Kubernetes - kubectl apply command

 kubectl apply command
# cat nginx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: front-end-service
  sepc: 
    containers:
    - name: nginx-container
      image: nginx:1.19
# kc apply-f naginx.yaml
live update definition
when you run apply command, if object is not created, it  will create it.

when you run this command, the yaml format is converted to json format and is stored as last applied configuration.

when you updated say verison of nginx to 1:19, in our local file and run kubectl apply command,
this value willbe compare with live config file. if there is difference, live config is updated with the 
new value. after apply, the last updated configuration json file is updated at last.
Last updated configuration file is always uptodated.
say, if one of the field is deleted,  and run apply command, and your last updated config file and that file available, 
then it will remove from live configuration.
so, we have three copy of configuration file

1) your local copy that you created
nginx.yaml
2) last applied configuration on the system
in JSON format
3) live object configuration file
you can modify it on the fly.
Note: if you use apply option, live object config has entry for last-applied-configuration
create/replace wont add entry to live config file..
apply command checks all three files.





No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...