Self-hosted mocks

Enterprise and uses: Insomnia

Insomnia allows Enterprise users to create self-hosted mock servers.

Configuration details and a Docker image can be found on GitHub.

You can run it locally with NodeJS or Docker, or you can use Kubernetes.

Create a self-hosted mock server with Kubernetes

Configure the deployment

Run the following command to create a deployment for your mock server:

echo "
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: insomnia-mock
    namespace: mock
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: insomnia-mock
    template:
      metadata:
        labels:
          app: insomnia-mock
      spec:
        containers:
        - name: insomnia-mock
          image: ghcr.io/kong/insomnia-mockbin:master
          ports:
          - containerPort: 9080
          env:
            - name: MOCKBIN_PORT
              value: '9080'
" | kubectl apply -f -

Configure the service

Run the following command create a service to expose Mockbin internally in the cluster:

echo "
  apiVersion: v1
  kind: Service
  metadata:
    name: insomnia-mock
    namespace: mock
  spec:
    type: ClusterIP
    ports:
    - name: mock
      port: 9080
      targetPort: 9080
    selector:
      app: insomnia-mock
" | kubectl apply -f -

Configure the Ingress

Run the following command to configure the Ingress to manage external access. This configuration will depend on your specific domain and TLS requirements.

For this example, you’ll need to export a domain and a TLS secret name as environment variables:

export DOMAIN='your-domain'
export SECRET_NAME='your-tls-secret-name'

Then run the following command:

echo "
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: insomnia-mock-ingress
    namespace: mock
  spec:
    ingressClassName: nginx
    rules:
    - host: $DOMAIN
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: insomnia-mock
              port:
                number: 9080
    tls:
    - hosts:
      - $DOMAIN
      secretName: $SECRET_NAME
" | kubectl apply -f -

Validate

Use the following commands to check the status of your resources:

kubectl get deployments -n mock
kubectl get services -n mock
kubectl get ingress -n mock

Once your mock is deployed, you can point your front-end application to the mock URL.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!