The motiviation for this gist was the deprecation of the --export flag. Having the yaml definition of a running deployment has the advantage that it can be saved and edited. For example when updating the version of an image.
For this example we will just use a deployment of the Kubernetes Deployment documentation. This can be deployed using the command
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
To get the yaml definition the get
command can be used:
kubectl get -o=yaml deployments.apps nginx-deployment > /tmp/export.yml
Since the aim of this example is to edit and rollout the changes the output is redirect to a file > /tmp/export.yml
The saved definition contains some information that is not needed:
metadata:
annotations:
deployment.kubernetes.io/revision: "4"
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"nginx"},"name":"nginx-deployment","namespace":"default"},"spec":{"progressDeadlineSeconds":600,"replicas":3,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app":"nginx"}},"strategy":{"rollingUpdate":{"maxSurge":"25%","maxUnavailable":"25%"},"type":"RollingUpdate"},"template":{"metadata":{"creationTimestamp":null,"labels":{"app":"nginx"}},"spec":{"containers":[{"image":"nginx:1.8.1","imagePullPolicy":"IfNotPresent","name":"nginx","ports":[{"containerPort":80,"protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File"}],"dnsPolicy":"ClusterFirst","restartPolicy":"Always","schedulerName":"default-scheduler","securityContext":{},"terminationGracePeriodSeconds":30}}}}
creationTimestamp: "2019-12-23T13:16:24Z"
generation: 4
labels:
app: nginx
name: nginx-deployment
namespace: default
resourceVersion: "2193"
selfLink: /apis/apps/v1/namespaces/default/deployments/nginx-deployment
uid: 1c7f7359-4f28-4116-b5a1-a10ebe218f0c
...
status:
availableReplicas: 3
conditions:
- lastTransitionTime: "2019-12-23T13:16:54Z"
lastUpdateTime: "2019-12-23T13:16:54Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
Actually most of the metadata can be deleted expect name
, namespace
, your own lables and annotations. The status
part is not needed at all.
After the removal of these parts the deployment can be edited and updated using Declarative deployment