---
# System prepended metadata

title: Simulation

---

# Simulation
- This document mainly describe the simulation and experiment setup in IEEE1935 edge computing testbed system.

## Prerequisites：
1. Several static public IP(depends on how many clusters you want to have).
2. Several server(At least 1 physical machines for each cluster. That is, you may build a cluster using VMs on a physical machine) used as control and compute nodes(depends on how many clusters and how complex these clusters you want).

## Orchestrator level:

### How to prepare a virtual node:
- Create and modify the VM setting with the following command:
    - You may find the image k8s_base.ova in the misc diretory.
```
vboxmanage import k8s_base.ova --vsys 0 --vmname {vmname} --cpus {#CPU} --memory {#memory}
vboxmanage modifyvm {vmname} --nic1 bridged --bridgeadapter1 {nic_name}
vboxmanage startvm {vmname} --type headless
```
- Check the IP address of the node:
```
vboxmanage showvminfo {vmname} | grep MAC
arp-scan -l | grep {MAC-address}
```

### Control Node settings:
- Init the cluster with the following command (run as a root user):
```
kubeadm init --apiserver-advertise-address={ip} --pod-network-cidr=172.16.0.0/16 --node-name={node_name}
```
- Cluster setting after init command (run as normal user):
```
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```
- Install calico pods:

```
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.0/manifests/calico.yaml
```

- Git Clone the microservice repo:
```
git clone https://github.com/Bhoopesh123/OpenTelemetry
cd opentelemetry-app
```

- Modify the yaml files at cluster 1:
    - Remove service deployment yaml file for currencyservice.
    ```
    rm deploy-currencyservice.yml
    ```
    - Add endpointslice for the service at currencyservice microservice.
    ```
    apiVersion: discovery.k8s.io/v1
    kind: EndpointSlice
    metadata:
      name: opentelemetry-demo-currencyservice-endpoint

      labels:
        kubernetes.io/service-name: opentelemetry-demo-currencyservice
    addressType: IPv4
    ports:
      - name: tcp-service
        port: {port}
    endpoints:
      - addresses:
        - "{ip-addr}"
    ```
    
- Create yaml files at cluster 2:
    - Create service-currencyservice.yml.
    ```
    apiVersion: v1
    kind: Service
    metadata:
      name: opentelemetry-demo-currencyservice
      labels:

        opentelemetry.io/name: opentelemetry-demo-currencyservice
        app.kubernetes.io/instance: opentelemetry-demo
        app.kubernetes.io/component: currencyservice
        app.kubernetes.io/name: opentelemetry-demo-currencyservice
        app.kubernetes.io/version: "1.5.0"
        app.kubernetes.io/part-of: opentelemetry-demo
    spec:
      type: NodePort
      ports:
        - port: 8080
          name: tcp-service
          targetPort: 8080
      selector:

        opentelemetry.io/name: opentelemetry-demo-currencyservice
    ```
    - Create deploy-currencyservice.yml.
    ```
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: opentelemetry-demo-currencyservice
      labels:

        opentelemetry.io/name: opentelemetry-demo-currencyservice
        app.kubernetes.io/instance: opentelemetry-demo
        app.kubernetes.io/component: currencyservice
        app.kubernetes.io/name: opentelemetry-demo-currencyservice
        app.kubernetes.io/version: "1.5.0"
        app.kubernetes.io/part-of: opentelemetry-demo
    spec:
      selector:
        matchLabels:

          opentelemetry.io/name: opentelemetry-demo-currencyservice
      template:
        metadata:
          labels:

            opentelemetry.io/name: opentelemetry-demo-currencyservice
            app.kubernetes.io/instance: opentelemetry-demo
            app.kubernetes.io/component: currencyservice
            app.kubernetes.io/name: opentelemetry-demo-currencyservice
        spec:
          serviceAccountName: opentelemetry-demo
          containers:
            - name: currencyservice
              image: 'ghcr.io/open-telemetry/demo:1.5.0-currencyservice'
              imagePullPolicy: IfNotPresent
              ports:

              - containerPort: 8080
                name: service
              env:
              - name: OTEL_SERVICE_NAME
                valueFrom:
                  fieldRef:
                    apiVersion: v1
                    fieldPath: metadata.labels['app.kubernetes.io/component']
              - name: OTEL_COLLECTOR_NAME
                value: 'opentelemetry-demo-otelcol'
              - name: OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
                value: cumulative
              - name: CURRENCY_SERVICE_PORT
                value: "8080"
              - name: OTEL_EXPORTER_OTLP_ENDPOINT
                value: http://$(OTEL_COLLECTOR_NAME):4317
              - name: OTEL_RESOURCE_ATTRIBUTES
                value: service.name=$(OTEL_SERVICE_NAME),service.namespace=opentelemetry-demo
              resources:
                limits:
                  memory: 20Mi
    ```
    
- Expose the local nodeport service to the public ip through GUI.
- Some useful debugging tools: grpcurl.

### Compute node settings:
- Use the following command to join the cluster(run as root user).
    - The join_command could be found after the initialization of the cluster on the control node.
```
{join_command} --ignore-preflight-errors=all --node-name={node_name}
```

## Control Node level:
