Using Kubernetes

Find the video guide for below instructions over here.

In this guide, we will be using Goreplay to mirror the traffic to HyperTest. Goreplay will be added as a sidecar container in your deployment.

Update your application's deployment as per the below example

You can add Goreplay as a sidecar by either directly editing your application deployment file or by using kubectl patch commands to patch the deployment.

Please note that if you use kubectl patch method, the changes will be lost when the deployment gets deleted. You will have to patch the deployment again

Required Parameters to run Goreplay:

  1. APPLICATION_PORT: <port on which your app is running>

  2. HYPERTEST_LOGGER_URL: <hypertest-vm-ip>:<hypertest-logger-port> or <hypertest_service_logger_ingress_url>

  3. HT_ENV: <your env name> # for eg: test, staging, etc

Edit the application's deployment file

Edit the application's deployment file and add Goreplay as sidecar container.

Only copy the parts from ## copy from this till ## to this. Rest is just sample manifest file

For below example, we have a node-app deployment where we are adding a Goreplay sidecar container.

node-app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app-deployment
  namespace: default
  labels:
    app: node-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app 
    spec:
      containers:
      - name: node-app
        image: <your-application-image>
        ports:
        - containerPort: <your-application-port>
      ## copy from this
      - name: goreplay
        image: public.ecr.aws/hypertestco/goreplay:0.16.1-24-02-2023
        env:
          - name: APPLICATION_PORT
            value: "<application-port>" # port on which your app is running
          - name: HYPERTEST_LOGGER_URL
            value: "<hypertest-logger-url>" #for eg: 1.2.3.4:8000
          - name: HT_ENV
            value: "<your env>" # for eg: test, staging etc
      ## to this

Apply the manifest file using below command

kubectl apply -f node-app.yaml

Check if the pod is up and running with 2 containers ( 1 additional goreplay) using below command (give appropriate namespace)

kubectl get po 
NAME                        READY   STATUS    RESTARTS   AGE
node-app-586b59d6f4-kgj47   2/2     Running   0          53s

Now traffic coming to this app is being mirrored to HyperTest.

To Verify the mirroring setup, hit any api on the application and check for request in "last mirrored requests" section or Session page in HyperTest.

Debug mirroring setup via Goreplay

To debug if goreplay is receiving the traffic from your application, we will output the incoming traffic to stdout, so we can see if Goreplay is receiving requests.

Steps:

  1. Exec into the goreplay container using below command:

kubectl exec -it <pod-name> -c goreplay sh

2. Run the following command:

sh debug-goreplay.sh

Now hit any api on your application and verify if Goreplay is able to receive it.

ALTERNATE WAY

Another way to add Goreplay is to directly patch the deployment. If you have edited your deployment using above method, you don't need to do this.

Patch an existing deployment via kubectl

Create a file with below content

patch-app-with-goreplay.yaml
spec:
  template:
    spec:
      containers:
      - name: goreplay
        image: public.ecr.aws/hypertestco/goreplay:0.16.1-24-02-2023
        env:
          - name: APPLICATION_PORT
            value: "<application-port>" # port on which your app is running
          - name: HYPERTEST_LOGGER_URL
            value: "<hypertest-logger-url>" # for eg: 1.2.3.4:8000
          - name: HT_ENV
            value: "<your env>" # for eg: test, staging etc

Apply the patch changes to your deployment using below command:

kubectl patch deployment <your-app-deployment-name> --patch-file patch-app-with-goreplay.yaml

Check if the pod is up and running with 2 containers using below command (give appropriate namespace)

kubectl get po 
NAME                        READY   STATUS    RESTARTS   AGE
node-app-586b59d6f4-kgj47   2/2     Running   0          53s

Now traffic coming to this application is being mirrored to HyperTest.

To verify the mirroring setup, hit any api on the application and check for request in "last mirrored requests" section or Session page in HyperTest.

Last updated