Kustomize is a tool for customizing Kubernetes configurations, simplifying the rollout and deployment of applications into clusters. It has the following features to manage application configuration files:
- generating resources from other sources
- setting cross-cutting fields for resources
- composing and customizing collections of resources_ In this scenario, you'll learn how to use Kustomize Bases and Overlays to deploy 3 different versions (Baseline, Staging, and Production) of the same sample web application into a provided Kubernetes cluster.
Blog Objectives:
Upon completion of this article, you should be able to:
- Use Kustomize to deploy a basic web application which has been packaged already into a docker image (hosted on DockerHub).
- Understand how to use configure and work with Kustomize Bases and Overlays
- Use Kustomize to generate 3 different enviroment specific deployments:
- Baseline - the baseline deployment version of the webapp
- Staging - uses a Kustomize overlay to change the baseline deployment settings
- Production - uses a Kustomize overlay to change the baseline deployment settings Test and validate the Base, Staging, and Production deployed cluster resources using the curl command and your workstations browser
You should:
- Be comfortable with basic Linux command line administration
- Be comfortable with basic Kubernetes and Container based concepts
The AWS Management Console is a web control panel for managing all your AWS resources, from EC2 instances to SNS topics. The console enables cloud management for all aspects of the AWS account, including managing security credentials and even setting up new IAM Users.
Instructions
- In the AWS Management Console search bar, enter EC2, and click the EC2 result under Services:
Click on Instances. Wait for the ide.cloudacademy.platform.instance EC2 instance to be launched, and then select it, and locate and copy the assigned IPv4 Public IP address. An example IPv4 address number is 54.69.21.244
The web-based CloudAcademy IDE has been configured on port 80. Using your browser, navigate to the IDE hosted on the ide.cloudacademy.platform.instance EC2 instance using the public IP address you just copied:
Note:
- Remember to use the public IP address assigned to your ide.cloudacademy.platform.instance.
- It takes approximately 1-2 minutes for the web-based CloudAcademy IDE service to startup on the ide.cloudacademy.platform.instance EC2 instance - try refreshing the browser page request until access is successful - please be patient.
- It has been configured to listen on port 80
- An example URL would be http://35.91.56.109 where "35.91.56.109" is the public IP from the last instruction
In this Lab Step, you'll use Kustomize to perform a baseline deployment of the sample web application into the provided Kubernetes cluster. Kustomize is now natively built into the standard kubectl command, which you'll use to drive the deployment. You'll then use your browser to confirm that the baseline version of the sample web application is indeed correctly deployed and configured.
Instructions
1. Expand the Files tree view by clicking on the Files tab on the left handside menu, and then open the project/code/kustomize/base directory:
The base directory contains the following 4 manifest files which are used to create a basic sample web application within the cluster. Open each of the following files within the editor view and then review their contents.
- configmap.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
The base directory also contains a kustomization.yaml file, which consists of the following configuration:
*Copy code
*
commonLabels:
app: webapp
env: base
version: "1.02"
org: cloudacademy.com
team: devops.labs
developer: jeremy.cook
resources:
- configmap.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
The commonLabels section defines common metadata labels which get copied into each of the 4 manifest files declared in the resources section when Kustomize is executed.
- Start a new terminal session by right clicking on the kustomize directory within the Files tree view and then selecting the Open in Terminal option: 6. Confirm that you are in the /home/project/code/kustomize directory. In the terminal execute the following command:
**Copy code
`cd /home/project/code/kustomize && ls -la
. Use Kustomize to generate and output the set of API resources as declared within the kustomization.yaml file within the base directory. In the terminal execute the following command:
kubectl kustomize base
Now use Kustomize to deploy the same baseline set of resources into the provided Kubernetes cluster. In the terminal execute the following command:
Confirm that all cluster resources were created successfully. In the terminal execute the following command:
Kubectl get all
The sample web application should now be ready to serve Internet based traffic via its assigned FQDN host declared within the base/ingress.yaml file. Display the contents of the base/ingress.yaml file. In the terminal execute the following command:
For your convenience the same FQDN host has been stored in the WEBAPP_URL_BASE environment variable. It can be retrieved by running the following command within the terminal:
Take note of the "Base" text and yellow background colour of the rendered web page. These settings are declared within the base/configmap.yaml file, which is itself referenced by the base/deployment.yaml file:
Introduction
In this Lab Step, you'll use Kustomize to perform the staging deployment of the sample web application into the provided Kubernetes cluster. You'll then use your browser to confirm that the staging version of the sample web application is indeed correctly deployed and configured.
Instructions
1. Expand the Files tree view by clicking on the Files tab on the left handside menu, and then open the project/code/kustomize/overlays/staging directory:
The staging directory contains 2 x k8s manifest files and 1 x kustomize config file. The k8s manifest files contain updated settings which will be used to create the staging sample web application resources within the k8s cluster. Open each of the following files within the editor view and review their contents.
- configmap.yaml - note the updated message and bgcolor values
- ingress.yaml - note the updated host value
The staging directory contains a kustomization.yaml file with the following configuration:
Copy code
`
namePrefix: stg-
commonLabels:
env: staging
commonAnnotations:
note: staging deployment of cloudacademy lab webapp
bases:
- ../../base
`
`
patchesStrategicMerge:
configmap.yaml
ingress.yaml
`
Notes:namePrefix defines a string that is added to the start of all resource names
commonLabels defines metadata labels that are added to all resources
commonAnnotations defines metadata annotations that are added to all resources
bases defines the base directory which is to be merge patched with the resources declared in the patchesStrategicMerge section
Start a new terminal session by right clicking on the staging directory within the Files tree view and then selecting the Open in Terminal option:
Confirm that you are in the /home/project/code/kustomize/overlays/staging directory. In the terminal execute the following command:
cd /home/project/code/kustomize/overlays/staging && ls -la
Use Kustomize to generate and output the set of API resources as declared within the kustomization.yaml file within the staging (current) directory. In the terminal execute the following command:
`
Copy code
kubectl kustomize .
`
. Now use Kustomize to deploy the staging generated set of resources into the Kubernetes cluster. In the terminal execute the following command:
*Copy code
*kubectl apply -k .
The staging sample web application should now be ready to serve Internet based traffic via its assigned FQDN host declared within the staging/ingress.yaml file. Display the contents of the staging/ingress.yaml file. In the terminal execute the following command:
Copy code
cat ingress.yaml
For your convenience the same FQDN host has been stored in the WEBAPP_URL_STAGING environment variable. It can be retrieved by running the following command within the terminal:
**Copy code
export | grep WEBAPP_URL_STAGING
Using your own web browser, browse to the URL stored in the WEBAPP_URL_STAGING environment variable and confirm that the staging sample web application renders successfully:
- Take note of the "Staging" text and the orange background colour of the rendered web page. These settings are declared within the staging/configmap.yaml file, which is itself referenced by the base/deployment.yaml file:
Copy code
apiVersion: v1
kind: ConfigMap
metadata:
name: webapp-cfg
data:
message: "Staging"
bgcolor: "orange"
- Close all currently open files within the editor.
- Close the currently opened terminal session (bottom) pane - leaving the IDE open. The production directory contains 3 x k8s manifest files and 1 x kustomize config file. The k8s manifest files contain updated settings which will be used to create the production sample web application within the cluster. Open each of the following files within the editor view and review their contents.
- configmap.yaml - note the updated message and bgcolor values
- deployment.yaml - note the updated replicas value
- ingress.yaml - note the updated host value
- The production directory contains a kustomization.yaml file with the following configuration:
Copy code
namePrefix: prod-
commonLabels:
env: prod
commonAnnotations:
note: production deployment of cloudacademy lab webapp
bases:
- ../../base
patchesStrategicMerge:
configmap.yaml
deployment.yaml
ingress.yaml
Notes:namePrefix defines a string that is added to the start of all resource names
commonLabels defines metadata labels that are added to all resources
commonAnnotations defines metadata annotations that are added to all resources
bases defines the base directory which is to be merge patched with the resources declared in the patchesStrategicMerge section
Start a new terminal session by right clicking on the production directory within the Files tree view and then selecting the Open in Terminal option:
5. A new terminal session is presented in the bottom pane:
6. Confirm that you are in the /home/project/code/kustomize/overlays/production directory. In the terminal execute the following command:
*Copy code
*
cd /home/project/code/kustomize/overlays/production && ls -la
7. Use Kustomize to generate and output the set of API resources as declared within the kustomization.yaml file within the production (current) directory. In the terminal execute the following command:
*Copy code
*
kubectl kustomize .
8. Now use Kustomize to deploy the production generated set of resources into the Kubernetes cluster. In the terminal execute the following command:
*Copy code
*
kubectl apply -k .
- Confirm that all production cluster resources were created successfully. In the terminal execute the following command:
*Copy code
*
kubectl get all -l env=prod
- The production sample web application should now be ready to serve Internet based traffic via its assigned FQDN host declared within the production/ingress.yaml file. Display the contents of the production/ingress.yaml file. In the terminal execute the following command:
*Copy code
*
cat ingress.yaml
- For your convenience the same FQDN host has been stored in the WEBAPP_URL_PROD environment variable. It can be retrieved by running the following command within the terminal:
**Copy code
`export | grep WEBAPP_URL_PROD
12. Using your own web browser, browse to the URL stored in the WEBAPP_URL_PROD environment variable and confirm that the production sample web application renders successfully:
- Take note of the "Production" text and the cyan background colour of the rendered web page. These settings are declared within the production/configmap.yaml file, which is itself referenced by the base/deployment.yaml file:
Copy code
apiVersion: v1
kind: ConfigMap
metadata:
name: webapp-cfg
data:
message: "Production"
bgcolor: "cyan"
Recourses
Top comments (0)