All Products
Search
Document Center

Alibaba Cloud Service Mesh:Deploy the HTTPBin application

Last Updated:Dec 13, 2023

HTTPBin is an open source application for testing and is commonly used for web debugging. After you deploy the HTTPBin application, you can easily view the methods, headers, and authorization information of HTTP requests. This topic describes how to deploy the HTTPBin application.

Prerequisites

Procedure

  1. Deploy the HTTPBin application in the Container Service for Kubernetes (ACK) cluster on the data plane.

    1. Use the following content to create an httpbin-application.yaml file:

      Expand to view the httpbin-application.yaml file

      apiVersion: v1
      kind: ServiceAccount
      metadata:
        name: httpbin
      ---
      apiVersion: v1
      kind: Service
      metadata:
        name: httpbin
        labels:
          app: httpbin
          service: httpbin
      spec:
        ports:
        - name: http
          port: 8000
          targetPort: 80
        selector:
          app: httpbin
      ---
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: httpbin
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: httpbin
            version: v1
        template:
          metadata:
            labels:
              app: httpbin
              version: v1
          spec:
            serviceAccountName: httpbin
            containers:
            - image: docker.io/kennethreitz/httpbin
              imagePullPolicy: IfNotPresent
              name: httpbin
              ports:
              - containerPort: 80
    2. Use kubectl to connect to the ACK cluster and run the following command to deploy the HTTPBin application:

      kubectl apply -f httpbin-application.yaml
  2. Configure a traffic rule for the HTTPBin application.

    1. Use the following content to create an Istio gateway. For more information, see Manage Istio gateways.

      apiVersion: networking.istio.io/v1beta1
      kind: Gateway
      metadata:
        name: httpbin
        namespace: default
      spec:
        selector:
          istio: ingressgateway
        servers:
          - hosts:
              - '*'
            port:
              name: test
              number: 80
              protocol: HTTP
    2. Use the following content to create a virtual service. For more information, see Manage virtual services.

      apiVersion: networking.istio.io/v1beta1
      kind: VirtualService
      metadata:
        name: httpbin-vs
        namespace: default
      spec:
        gateways:
          - httpbin
        hosts:
          - '*'
        http:
          - name: test
            route:
              - destination:
                  host: httpbin.default.svc.cluster.local
                  port:
                    number: 8000
  3. Perform access tests.

    Replace the IP address of the ASM gateway in the following commands with the actual IP address of the ASM gateway. For more information about how to obtain the IP address of an ASM gateway, see Obtain the IP address of the ingress gateway.

    1. Run the following command to access the /status/200 path of the HTTPBin application:

      curl http://${IP address of the ASM gateway}/status/200 -v

      200 OK is returned.

    2. Run the following command to access the /status/418 path of the HTTPBin application:

      curl http://${IP address of the ASM gateway}/status/418 -v

      418 Unknown is returned.

    3. Run the following command to access the /status/403 path of the HTTPBin application:

      curl http://${IP address of the ASM gateway}/status/403 -v

      403 Forbidden is returned.

    4. Run the following command to access the /headers path of the HTTPBin application:

      curl http://${IP address of the ASM gateway}/headers -H test-header:test-value -v

      The response contains the headers carried in the request.