As a Automation Pipelines administrator or developer, you can use Automation Pipelines and VMware Tanzu Kubernetes Grid Integrated Edition (formerly known as VMware Enterprise PKS) to automate the deployment of your software applications to a Kubernetes cluster. This use case mentions other methods that you can use to automate the release of your application.
In this use case, you will create a pipeline that includes two stages, and will use Jenkins to build and deploy your application.
- The first stage is for development. It uses Jenkins to pull your code from a branch in your GitHub repository, then build, test, and publish it.
- The second stage is for deployment. It runs a user operation task that requires approval from key users before the pipeline can deploy your application to your Kubernetes cluster.
When using a Kubernetes API endpoint in the pipeline workspace, Automation Pipelines creates the necessary Kubernetes resources such as ConfigMap, Secret, and Pod to run the continuous integration (CI) task or custom task. Automation Pipelines communicates with the container by using the NodePort.
To share data across pipeline runs, you must provide a persistent volume claim, and Automation Pipelines will mount the persistent volume claim to the container to store the data, and use it for subsequent pipeline runs.
The Automation Pipelines pipeline workspace supports Docker and Kubernetes for continuous integration tasks and custom tasks.
For more information about configuring the workspace, see Configuring the Pipeline Workspace.
The development tools, deployment instances, and pipeline YAML file must be available so that your pipeline can build, test, publish, and deploy your application. The pipeline will deploy your application to development and production instances of Kubernetes clusters.
Other methods that automate the release of your application:
- Instead of building your application by using Jenkins, you can use the Automation Pipelines native build capability and a Docker build host.
- Instead of deploying your application to a Kubernetes cluster, you could deploy it to an Amazon Web Services (AWS) cluster.
For more information about using the Automation Pipelines native build capability and a Docker host, see:
Prerequisites
- Verify that the application code to deploy resides in a working GitHub repository.
- Verify that you have a working instance of Jenkins.
- Verify that you have a working email server.
- In Automation Pipelines, create an email endpoint that connects to your email server.
- Set up two Kubernetes clusters on Amazon Web Services (AWS), for development and production, where your pipeline will deploy your application.
- Verify that the GitHub repository contains the YAML code for your pipeline, and alternatively a YAML file that defines the metadata and specifications for your environment.
Procedure
Results
Congratulations! You automated the deployment of your software application to your Kubernetes cluster.
Example: Example pipeline YAML that deploys an application to a Kubernetes cluster
For the type of pipeline used in this example, the YAML resembles the following code:
apiVersion: v1 kind: Namespace metadata: name: ${input.GIT_BRANCH_NAME} namespace: ${input.GIT_BRANCH_NAME} --- apiVersion: v1 data: .dockercfg: eyJzeW1waG9ueS10YW5nby1iZXRhMi5qZnJvZy5pbyI6eyJ1c2VybmFtZSI6InRhbmdvLWJldGEyIiwicGFzc3dvcmQiOiJhRGstcmVOLW1UQi1IejciLCJlbWFpbCI6InRhbmdvLWJldGEyQHZtd2FyZS5jb20iLCJhdXRoIjoiZEdGdVoyOHRZbVYwWVRJNllVUnJMWEpsVGkxdFZFSXRTSG8zIn19 kind: Secret metadata: name: jfrog namespace: ${input.GIT_BRANCH_NAME} type: kubernetes.io/dockercfg --- apiVersion: v1 kind: Service metadata: name: pipelines namespace: ${input.GIT_BRANCH_NAME} labels: app: pipelines spec: ports: - port: 80 selector: app: pipelines tier: frontend type: LoadBalancer --- apiVersion: extensions/v1 kind: Deployment metadata: name: pipelines namespace: ${input.GIT_BRANCH_NAME} labels: app: pipelines spec: selector: matchLabels: app: pipelines tier: frontend strategy: type: Recreate template: metadata: labels: app: pipelines tier: frontend spec: containers: - name: pipelines image: cas.jfrog.io/pipelines:${input.GIT_BRANCH_NAME}-${Dev.PublishApp.output.jobId} ports: - containerPort: 80 name: pipelines imagePullSecrets: - name: jfrog
What to do next
To deploy your software application to your production Kubernetes cluster, perform the steps again and select your production cluster.
To learn more about integrating Automation Pipelines with Jenkins, see How do I integrate Automation Pipelines with Jenkins.