Generating Kubernetes resources from files

Let's learn how to customize the nginx rollout we did in the previous recipe using Kustomize this time:

  1. Create a directory named nginx:
$ mkdir nginx
  1. Copy the deployment-nginx.yaml file you created in the Deploying workload using YAML files recipe under the nginx directory. This file still uses image: nginx:1.7.9 as the container image:
$ cp deployment-nginx.yaml ./nginx/
  1. Create a kustomization.yaml file by specifying a new image version:
$ cat <<EOF >./nginx/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment-nginx.yaml
images:
- name: nginx
newName: nginx
newTag: 1.16.0
commonAnnotations:
kubernetes.io/change-cause: "Initial deployment with 1.16.0"
EOF

  1. Check that the new version is injected into your Deployment by running the following command. In the output, you will see image: nginx:1.16.0 instead of the original image version nginx:1.7.9 that we have previously used in the deployment-nginx.yaml file:
$ kubectl kustomize ./nginx/
  1. Apply the Deployment with customizations using the -k parameter:
$ kubectl apply -k nginx
  1. Create a new kustomization.yaml file by specifying a newer image version:
$ cat <<EOF > nginx/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment-nginx.yaml
images:
- name: nginx
newName: nginx
newTag: 1.17.0
commonAnnotations:
kubernetes.io/change-cause: "image updated to 1.17.0"
EOF
  1. Apply the customized Deployment using the -k parameter:
$ kubectl apply -k nginx
  1. Now, display the rollout history for the Deployment:
$ kubectl rollout history deployment nginx-deployment
deployment.extensions/nginx-deployment
REVISION CHANGE-CAUSE
1 Initial deployment with 1.16.0
2 image updated to 1.17.0

Now you have learned how to edit, scale up, and also roll out a new version of the application using Kustomize.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.157.142