Lab 04: Exposing Your Application

In this lab, we will deploy a sample application to a Kubernetes cluster. The application will be automatically exposed using NodePort. NodePort is a simple way to make your application accessible from outside the Kubernetes cluster. It is primarily used for testing purposes and is not recommended for production environments.

Deployment Instructions

  1. Deploy the Application:
    • Navigate to the main directory of the application by entering the root path / in your terminal.
    • Deploy the application to the cluster by running the following command:
      make deploy
      
  2. Access the Deployed Services: Once the deployment is complete, several services including Zipkin, Swagger, Prometheus, Grafana, and a Node.js application will be running and exposed on various ports. To explore these services, follow the instructions below:
    • Zipkin:
      • Zipkin is used for tracing network requests within your application.
      • To access Zipkin, check the ports section in your terminal and navigate to the port 9411.
      • To try out Zipkin with sample data, download the following JSON file and upload it to Zipkin:
        https://github.com/openzipkin/zipkin/blob/master/zipkin-lens/testdata/ascend.json
        
    • Prometheus:
      • Prometheus is used for monitoring the application. It allows you to see which APIs are currently down.
      • To access Prometheus, navigate to port 30000.
      • In Prometheus, go to the "Targets" section to view the status of various APIs. For this lab, some APIs are intentionally set to be down and will be brought up later.
    • Grafana:
      • Grafana is used for visualizing metrics through graphs.
      • To access Grafana, navigate to port 32000.

Resetting Grafana Admin Password

If you encounter issues logging into Grafana with the expected credentials, for learning purposes, you can reset the admin password using the following steps:

  1. Retrieve the name of the Grafana pod:
    kubectl get pods -n monitoring
    
  2. Exec into the Grafana pod:
    kubectl exec -it <grafana-pod-name> -n monitoring -- /bin/sh
    
  3. Reset the admin password:
    grafana-cli admin reset-admin-password newpassword
    

    your username is admin and password is newpassword

Importing a Prometheus Dashboard into Grafana

To visualize Prometheus metrics in Grafana, you can import pre-configured dashboards. Here’s how to import a Prometheus dashboard:

  1. Access Grafana: Log in to your Grafana instance using the admin credentials.
  2. Open the Dashboard Import Interface:
    • From the Grafana main menu, select the "+" icon on the left sidebar.
    • Choose "Import".
  3. Import Dashboard:
    • You can import a dashboard using a dashboard ID from Grafana.com Dashboards, or by uploading a JSON file.
    • To import a dashboard from Grafana.com, enter the dashboard ID (e.g., 1860 for a popular Node Exporter dashboard) into the “Import via grafana.com” field and click "Load".
    • Alternatively, if you have a dashboard JSON file, click "Upload JSON file" and select the file from your computer.
  4. Select Prometheus as the Data Source:
    • During the import process, you will be asked to select a data source.
    • Choose "Prometheus" from the dropdown menu.
  5. Finalize Import:
    • After selecting the data source, click "Import" to complete the process.

You should now see the imported dashboard with metrics from your Prometheus data source.

Now we learn how to expose the apps. In the next section, we will learn how we can scale a Node.js application.