Skip to main content
Welcome to this step-by-step guide on deploying and validating the Login App on Kubernetes. In this tutorial, you’ll learn how to verify your Elasticsearch and Kibana pods, explore the repository structure, review Kubernetes deployment files, deploy your application, and examine logging and authentication details. Let’s dive into the lab!

Verifying Elasticsearch and Kibana Pods

Before deploying the Login App, ensure that your Elasticsearch and Kibana pods are up and running. Execute the following command:
You should see an output similar to this:
Both services must be active for the Login App deployment to work correctly.
If either service is not in the Running state, verify your setup and resolve any issues before proceeding.

Cloning the Repository and Exploring the File Structure

First, clone the GitHub repository that contains all the necessary application files:
After cloning, navigate into the repository and list the files and directories:
The directory structure should look similar to this:
Focus on the python-webapp directory. Change into this directory:
The output should list the following files and directories:
The templates directory contains the CSS and HTML files for the Login App. Configuration files such as service.yaml and deployment.yaml will be applied later, while requirements.txt and app.py contain the necessary dependencies and application code. The Dockerfile is used to build your Docker image, which is available on Docker Hub.

Reviewing Kubernetes Deployment Files

Next, navigate to the Kubernetes deployment folder to review the deployment configuration:
Within this folder, you will find several files, including configurations for Fluent Bit, as well as two critical files for our Python application:
  • python-app-service.yaml
  • python-app-deployment.yaml
Let’s inspect the contents of python-app-deployment.yaml:
The file should resemble the following YAML configuration:
This YAML defines a Deployment that pulls the Docker image from Docker Hub. The container mounts a volume at /var/log/webapp, ensuring that the directory is created if it does not exist already. The associated service is defined as follows:
This service configuration exposes the application on port 5005 with a NodePort set within the allowed range. Adjust the nodePort value as needed while keeping it between 30000 and 32767.

Deploying the Application

Now that your configurations are in place, deploy the Login App by applying the deployment and service YAML files. Both files use the namespace “efk”:
After applying the configurations, verify that the pod is running:
Then, check the service to confirm that the NodePort is correctly exposed:
Open your browser and navigate to the NodePort address to view the Login App interface.

Testing the Login Functionality

On the Login App page, use the following credentials:
  1. Enter admin as the username.
  2. Enter password as the password.
  3. Click the login button.
A successful login displays a welcome page. For visual guidance, see the following images:
The image shows a login form with fields for a username and password, a login button, and a "problem?" link, set against a light blue background.
Upon successful login, the result should look similar to:
The image shows a light blue background with a white notification box in the center that reads, "Welcome to the WebApp! Login successful. You are now logged in."
If you use any incorrect credentials (for example, a username other than admin or an incorrect password), the login will fail:
The image shows a "Login Failed" message indicating invalid credentials, with instructions to proceed to the second level of authentication. The background is light blue.
Only the credentials admin/password are accepted; all others result in a login failure.

Verifying Application Logs

After interacting with the application, check the logs to monitor activities such as successful logins, weak password warnings, and failed attempts. Retrieve the logs with the following command:
The logs might include entries similar to:
These logs capture request details, including user agent, client IP, and response statuses. They also record warnings when weak passwords are used or if login attempts fail.

Understanding the Application’s Logging Mechanism

A detailed look at the app.py file shows how logging is implemented in the Login App. The logging module is configured to capture comprehensive details about each request and response. Key parts of the code include:
This configuration ensures every request, response, and significant action (like login success or failure) is logged thoroughly, enhancing monitoring and debugging capabilities.

Next Steps

The next phase of this lesson will cover configuring Fluent Bit to forward these logs to Elasticsearch, establishing a centralized logging and monitoring system. This topic will be explored in the subsequent lesson. Thank you for following along. For more detailed Kubernetes documentation and best practices, check out the Kubernetes Documentation and related resources. Happy Deploying!

Watch Video