Skip to content

Latest commit

 

History

History
298 lines (234 loc) · 10 KB

File metadata and controls

298 lines (234 loc) · 10 KB

Deploy a Kubernetes cluster on upcloud

Create a Kubernetes Cluster

Step 1: Cluster Configuration Log in to your UpCloud Control Panel. Navigate to Kubernetes and click Create Cluster.

  • Location: Choose a location (e.g., FI-HEL1 as shown below).
UpCloud – New Kubernetes cluster-1

Step 2: Network

  • Network: Check the Private Network option.

Important

Crucial Step: You MUST create/select a private network (e.g., k8s-private-net). This connects your worker nodes securely. Note that the private network cannot be changed once the cluster has been created

UpCloud – New Kubernetes cluster-2

Step 3: Node Group & SSH Configuration

  • Plan: Select a plan (e.g., Development or General Purpose). For this course, the 2 core, 4 GB memory (Development) plan with 2 nodes is sufficient.
  • Name: Give your node group a name (e.g., worker-group).
UpCloud – New Kubernetes cluster-3
  • SSH Key: It is highly recommended to add an SSH key to access your worker nodes if debugging is needed.
UpCloud – New Kubernetes cluster-4

Step 4: Create

  • Public Access: Ensure "Allow access from all IP addresses" is selected for the API unless you have a static IP. Review your summary and click Create cluster.

Note

Creating a Kubernetes cluster takes time (approximately 10 minutes). Please be patient while the status changes to Running.

UpCloud – New Kubernetes cluster-5

Connect to your cluster

Once the cluster status is Running, you need to configure your local environment to control it.

Step 1: Install kubectl If you haven't already, install the Kubernetes command-line tool: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux

Step 2: Configure kubeconfig

  1. Go to the Kubernetes tab in UpCloud.
  2. Scroll down to the Kubeconfig section.
  3. Recommended to configure the kubeconfig file manually. Click Download kubeconfig to save the YAML file to your local machine (e.g., ~/Downloads/coursetestcluster_kubeconfig.yaml).
  4. Export KUBECONFIG that you downloaded above (use full path).
export KUBECONFIG=~/Downloads/coursetestcluster_kubeconfig.yaml

Tip

To make this permanent for the current session, you can add it to your shell profile (~/.bashrc or ~/.zshrc), or simply run this command every time you open a new terminal window to work on this project.

upcloud_kubeconfig

Step 3: Verify Connection Run the following command to check if you are connected:

kubectl cluster-info

Expected Output:

Kubernetes control plane is running at https://xxxxxx
CoreDNS is running at https://xxxxxx

Deploy hotelReservation microservice system

Clone the repo

git clone https://github.com/EvoTestOps/DeathStarBench.git

Build docker images (Optional)

Pre-requirements:

  • Docker
  • Docker-compose
  • luarocks (apt-get install luarocks)
  • luasocket (luarocks install luasocket)

Before you start

  1. Navigate to the scripts directory:
git clone https://github.com/EvoTestOps/DeathStarBench.git
cd DeathStarBench/hotelReservation/kubernetes/scripts
  1. Build the Docker images using the provided script:
./build-docker-images.sh

Important

If you want to use your own Docker registry, you need to:

  • Open build-docker-images.sh and modify the REGISTRY variable to your Docker username
  • Update all deployment YAML files in the kubernetes/ directory to use your modified image names
  • Example: Change igorrudyk1/user-service:latest to your-username/user-service:latest

Deploy services

kubectl apply -Rf DeathStarBench/hotelReservation/kubernetes/

Wait until the deployment is complete to view the result

kubectl get pods

Locust test

Install locust

  • Option.1: Using Conda We strongly recommend using Conda virtual environment to avoid technical problems:
conda create --name hotel python=3.11
conda activate hotel
conda install -c conda-forge locust
  • Option.2: Using pip
sudo apt-get update 
sudo apt install python3-pip
pip3 install locust
export PATH=$PATH:$HOME/.local/bin

Executing the test:

Wait for the external-IP of frontend (might take up to 10 minutes):

kubectl get svc frontend -w

Then run the Locust test:

locust -f uh_locust_tests/locust.py --host=http://<your-external-IP-of-frontend>:5000 --headless -u 10 -r 2 -t 10s

parameter description:--host means the address of host; --headless means not start the graphical interface and output the result in terminal;- u means the number of concurrent users; - r means the number of new users per second; -t means the duration of the test

Expected Output: You should see statistics about request success/failure rates.

Monitoring

For Task 1 and Task 2 reports, you need to observe the system status using these tools.

Trace (Jaeger)

Jaeger is used for distributed tracing to monitor and troubleshoot transactions in complex distributed systems.

Get the URL: Watch for the external-IP of jaeger:

kubectl get svc jaeger -w

Access UI: Visit http://<your-external-IP-of-jaeger>:16686 in your browser.

jaeger UI

How to use:

  • Search: Select a Service (e.g., frontend) and click "Find Traces".

  • Analyze: Click on a specific trace to see the Spans (individual operations).

  • Identify Issues: Look for:

    • Errors: Spans marked in red.

    • Latency: unusually long bars in the timeline.

    • Waterfall view: Helps you understand which microservice is slowing down the request.

jaeger waterfall

Metric (Prometheus)

Prometheus is used for event monitoring and alerting.

Setup

Go to the corresponding directory

cd <path-of-repo>/hotelReservation/UH_prometheus

Create a configmap

kubectl create configmap prometheus-config --from-file=prometheus.yml

Apply related resources

kubectl apply -f node-exporter-service.yaml
kubectl apply -f node-exporter.yaml
kubectl apply -f prometheus-config.yaml
kubectl apply -f prometheus-deployment.yaml
kubectl apply -f prometheus-rbac.yaml
kubectl apply -f prometheus-service.yaml

Get the URL: Gets the external IP of the prometheus service

kubectl get svc prometheus -w

Visit http://<your-external-IP-of-prometheus>:9090 in your browser. prometheus main ui

How to use:

  • Graph Tab: Enter queries to visualize data over time.

  • Table Tab: View the current value of metrics.

prometheus UI

Some sample query metrics

  • CPU utilization
rate(node_cpu_seconds_total{mode="system"}[1m])
  • Memory usage
node_memory_MemTotal_bytes - node_memory_MemFree_bytes
  • Disk usage
node_filesystem_size_bytes - node_filesystem_free_bytes

Logs

To debug specific pods (e.g., if a Locust test fails):

  1. Get pods name
kubectl get pods
  1. View the specific pod logs
kubectl logs <pod-name>

Kubernetes Common Commands Sheet

Pod Operations

# List all pods
kubectl get pods [-n namespace]

# Get pod details
kubectl describe pod <pod-name>

# Get pod logs
kubectl logs <pod-name>
kubectl logs -f <pod-name>    # Follow log output

# Execute command in pod
kubectl exec -it <pod-name> -- /bin/bash

# Delete pod
kubectl delete pod <pod-name>

Service Operations

# List all services
kubectl get services
kubectl get svc    # Short form

# Get service details
kubectl describe service <service-name>

# Port forwarding
kubectl port-forward svc/<service-name> <local-port>:<service-port>

Deployment Operations

# List deployments
kubectl get deployments

# Scale deployment
kubectl scale deployment <deployment-name> --replicas=<number>

# Rollout status
kubectl rollout status deployment/<deployment-name>

# Rollback deployment
kubectl rollout undo deployment/<deployment-name>

Namespace Operations

# List namespaces
kubectl get namespaces
kubectl get ns    # Short form

# Create namespace
kubectl create namespace <namespace-name>

# Switch namespace
kubectl config set-context --current --namespace=<namespace-name>

# Delete namespace (and everything in it)
kubectl delete namespace <namespace-name>

Note

Replace text in <> with your actual values. Add -n <namespace> to any command to specify a namespace.