Home  > Resources  > Blog

Prepare for Deploying an Application to Kubernetes

 
December 1, 2022 by Bibhas Bhattacharya
Category: DevOps

Flux uses GitOps principles to deploy applications to Kubernetes. Main benefits of this are:

  1. All k8s configuration yaml files are version controlled. We know exactly what changes were applied and when.
  2. Very few admin users will need access to the k8s cluster. All changes happen via pushing config files to a Git repo. This makes the cluster more secure.

Before we can deploy our application, we will do a few prerequisite work.

Part 1 – Create a GitHub Personal Access Token (PAT)

You will need a GitHub account. Gather the following for that account:

  1. User ID
  2. Password

1. Log into GitHub with your GitHuib account, create one if you don’t have one:

https://github.com

Next we need to create your GitHub personal access token.

2. Change the settings for your GitHub profile by clicking your profile image in the upper right, and then click Settings.

3. At the bottom of the left menu, click the <Developer settings> section.

4. Click the Personal access tokens → Tokens (classic) link.

5. If you already have a token, delete it.
6. Click Generate new token → Generate new token (classic).

7. Enter a text under Note.

8. Change expiration to No expiration.

9. Select repo inside Select scopes as shown below:

10. Scroll to the end and click Generate token.

You will see your new token:

11. Copy the token, you will need it during the lab.
12. Create a new text file, paste the token and save the file.
Leave this file open during the Lab to access it easily so you won’t lose the token.

Part 2 – Configure Git

1. Open a Terminal.
2. Run these commands to set the user’s full name and email. This information is used to identify the author when you commit files to a repo:

git config --global user.name "YOUR FULL NAME"
git config --global user.email <YOUR EMAIL ADDRESS>

For example:

git config --global user.name "Daffy Duck"
git config --global user.email daffy@wb.com

Part 3 – Get the Application Code

In this tutorial, you will deploy a very simple web application written in Java. Later, we will add Flux config files to this project. Let’s go ahead and fork the repo so that we can make changes to it.

1. Open a web browser and go to:

https://github.com/WebAgeSolutions/gitops-demo-webapp

2. On the top right corner you should see the Fork button. Click that.

3. You need to sign in into your GitHub account if you haven’t yet.

You will see:

4. Click Create fork to add a copy of the repo to your own account.

Now we can get the code in our local machine by cloning it.

5. Open a shell window and run these commands:

cd ~/
git clone https://github.com/<GITHUB_USER>/gitops-demo-webapp

[Replace <GITHUB_USER> with your own GitHub user id:]

Part 4 – Build and Push the Application’s Docker Image

Building and pushing of Docker images are often done by the developers and automated through the CI pipeline. This part of the process does not change when you use Flux.

To save time an image for our application called bibhas2/gitops-demo-webapp is already created and pushed to Docker Hub. We will use that image in this lab.

If you need to learn and practice how to create images then please follow the README.md file in the repo.

Part 5 – Review

In this tutorial, we did a few prerequisite tasks before we can deploy our application to K8s

Follow Us

Blog Categories