Environment Setup

Image

In this page, we will be discussing how to set up your environment, and make sure to run up the UI front end and the Book Review Service’s node server.

What does the final deliverable for this section look like?

  • You have a running Kubernetes (k8s) cluster on your local machine, with Knative installed.
  • You have your front end application deployed as Kubernetes deployment with port-forwarding to localhost:3000
  • You have your Node.js application deployed as Kubernetes deployment with port-forwarding to localhost:8080

We will be fulfilling each requirement with the order above.

Clone the Repository

Next Step Image

  1. git clone https://github.com/knative/docs.git

Troubleshooting

Having issue with cloning your repo? Check here for help.

Warning

IMPORTANT: Please take some time to read the Disclaimer before moving to the next page.

File Structure

Image

The code for the sample app is in docs/code-samples/eventing/bookstore-sample-app

Under bookstore-sample-app folder, there are 2 folders:

  • /solution: this folder contains all the yaml files, and the code you needed. Check it when you got stuck.

  • /start: this folder contains the necessary files for you to get started. Save there all the configuration files yourself following the tutorial!

Image

Tip

Kuack suggests you to start from /start, write all the configuration files as you go over the tutorial, and check solutions when you got stuck.

Image

Always cd back to the root directory, which is /start, before running any commands.

All the commands in the tutorial are written assuming you are in the /start directory.

Shortcut

Image

Running docs/code-samples/eventing/bookstore-sample-app/start/setup.sh will automatically complete all tasks in this section.

Warning

However, if you are not familiar with the process, we recommend reviewing the steps below.

Instructions

Task 1: Set Up a Running Kubernetes Cluster with Knative Installed

Image

Tip

We recommend you using kn quickstart plugin to install Knative.

Please follow the instructions here to spin up your cluster with Knative installed!

Verify

You should see the pods in the knative-eventing and knative-serving namespaces running before proceeding.

  1. NAMESPACE NAME READY STATUS RESTARTS AGE
  2. knative-eventing eventing-controller-7576f555d5-7c2p2 1/1 Running 0 4m50s
  3. knative-eventing eventing-webhook-5874bb8445-cqcn9 1/1 Running 0 4m50s
  4. knative-eventing imc-controller-8c5d5ddb5-m249l 1/1 Running 0 4m49s
  5. knative-eventing imc-dispatcher-76d9f7464b-dphd6 1/1 Running 0 4m49s
  6. knative-eventing mt-broker-controller-8d8f8d48f-rvlcv 1/1 Running 0 4m48s
  7. knative-eventing mt-broker-filter-85c457f879-dvhnj 1/1 Running 0 4m48s
  8. knative-eventing mt-broker-ingress-5688f4cd68-nm8cc 1/1 Running 0 4m48s
  9. knative-serving activator-55d856fccd-g5qpw 1/1 Running 0 4m53s
  10. knative-serving autoscaler-5fb49c64c7-hrjng 1/1 Running 0 4m53s
  11. knative-serving controller-ddbb9d4f-khttq 1/1 Running 0 4m53s
  12. knative-serving net-kourier-controller-68d89f78d5-hw8r6 1/1 Running 0 4m52s
  13. knative-serving webhook-85b9744fc5-6w9sg 1/1 Running 0 4m53s
  14. kourier-system 3scale-kourier-gateway-dbc5b88f5-7g29n 1/1 Running 0 4m52s
  15. kube-system coredns-5dd5756b68-49xsj 1/1 Running 0 12m
  16. kube-system etcd-minikube 1/1 Running 0 12m
  17. kube-system kube-apiserver-minikube 1/1 Running 0 12m
  18. kube-system kube-controller-manager-minikube 1/1 Running 0 12m
  19. kube-system kube-proxy-tqcvx 1/1 Running 0 12m
  20. kube-system kube-scheduler-minikube 1/1 Running 0 12m
  21. kube-system storage-provisioner 1/1 Running 0 12m

Extra Step for Minikube Users:

Image

Attention! In case you’re not using the Knative Quick Start, set up the tunnel manually to connect to services of type LoadBalancer:

Run the following command and keep the terminal open:

  1. minikube tunnel

Verify

If there aren’t any error messages, it means you have set up the tunnel successfully.

Task 2: Running the Bookstore Web App

Image

The Next.js frontend app is located in the docs/code-samples/eventing/bookstore-sample-app/start/frontend folder.

Ensure that port 3000 on your local machine is not being used by another application.

Deploy the Frontend App

You can either build the image locally or use our pre-built image. If you are using the pre-built image, you can proceed to the next step.

When ready, run the following command to deploy the frontend app:

  1. kubectl apply -f frontend/config/100-front-end-deployment.yaml

This will create the Deployment and expose it with a Service of type LoadBalancer to receive external traffic:

  1. deployment.apps/bookstore-frontend created
  2. service/bookstore-frontend-svc created

Verify

Run the following command to check if the pod is running:

  1. kubectl get pods

You will see that your front end pod is running.

  1. NAME READY STATUS RESTARTS AGE
  2. bookstore-frontend-7b879ffb78-9bln6 1/1 Running 0 4m37s

Port Forwarding (Optional under condition)

Image

You might need to set up port forwarding to access the app from your local machine.

Check if port forwarding is necessary by running:

  1. kubectl get services

And you will see the following console output:

  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  2. bookstore-frontend-svc LoadBalancer 10.99.187.173 <pending> 3000:31600/TCP 27m
  3. kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 39m

Note

If the EXTERNAL-IP for your frontend service is 127.0.0.1, port forwarding is not needed.

If port forwarding is required, run the following command:

  1. kubectl port-forward svc/bookstore-frontend-svc 3000:3000

You should see the following output:

  1. Forwarding from 127.0.0.1:3000 -> 3000
  2. Forwarding from [::1]:3000 -> 3000

Don’t close the terminal when port-forwarding is established. Start a new terminal to run the next command.

Verify

Visit http://localhost:3000 in your browser. The UI page should appear!

Image

Task 3: Running the Book Review Service

Image

The Node.js server is located in the node-server folder.

Warning

Ensure that port 8080 on your local machine is not being used by another application.

Deploy the Book Review Service: Node.js Server

You can either build the image locally or use our pre-built image. If you are using the pre-built image, you can proceed to the next step.

When ready, run the following command to deploy the Node.js server:

  1. kubectl apply -f node-server/config/100-deployment.yaml

This command will pull the image and deploy it to your cluster as a Deployment. It will also expose it as a LoadBalancer to receive external traffic.

  1. deployment.apps/node-server created
  2. service/node-server-svc created

Verify

Run the following command to check if the pod is running:

  1. kubectl get pods

You will see that your Node.js server (node-server) pod is running.

  1. NAME READY STATUS RESTARTS AGE
  2. bookstore-frontend-7b879ffb78-9bln6 1/1 Running 0 39m
  3. node-server-68bf98cdf4-skjmh 1/1 Running 0 38m

Port Forwarding (optional under condition)

Image

You might need to set up port forwarding to access the app from your local machine.

Check if port forwarding is necessary by running:

  1. kubectl get services

And you will see the following console output:

  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  2. bookstore-frontend-svc LoadBalancer 10.99.187.173 <pending> 3000:31600/TCP 73m
  3. kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 85m
  4. node-server-svc LoadBalancer 10.101.90.35 <pending> 80:31792/TCP 73m

Note

If the EXTERNAL-IP for your Node.js service is 127.0.0.1, port forwarding is not needed. If you failed to visit the page localhost:8080, you can try to set up port forwarding.

If port forwarding is required, open a new terminal and run:

  1. kubectl port-forward svc/node-server-svc 8080:80

You should see the following output:

  1. Forwarding from 127.0.0.1:8080 > 8000
  2. Forwarding from [::1]:8080 > 8000

Don’t close the terminal when port-forwarding is established. Start a new terminal to run the next command.

Verify

Visit http://localhost:8080 in your browser. The Node.js service should be up and running.

And in your front end page, you should see the status turns green and say “Connected to node server”.

Image

Troubleshooting

If you encounter any issues during the setup process, refer to the troubleshooting section in the documentation or check the logs of your Kubernetes pods for more details.

Troubleshooting

To check the logs, use the following command:

  1. kubectl logs <pod-name>

Replace <pod-name> with the name of the pod you want to check.

Next Step

Image

You have successfully set up the cluster with Knative installed, and running your front end app and node server. You are all set to start learning. Your journey begins from here.

Go to Lesson 1 - Send Review Comment to Broker Environment Setup - 图16