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
Deploy the HTTPBin application in the Container Service for Kubernetes (ACK) cluster on the data plane.
Use the following content to create an httpbin-application.yaml file:
Use kubectl to connect to the ACK cluster and run the following command to deploy the HTTPBin application:
kubectl apply -f httpbin-application.yaml
Configure a traffic rule for the HTTPBin application.
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: HTTPUse 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
Perform access tests.
Replace the
IP address of the ASM gatewayin the following commands with the actual IP address of the ASM gateway. For more information about how to obtain the IP address of the gateway, see Obtain the IP address of the ingress gateway.Run the following command to access the
/status/200path of the HTTPBin application:curl http://${IP address of the ASM gateway}/status/200 -v200 OKis returned.Run the following command to access the
/status/418path of the HTTPBin application:curl http://${IP address of the ASM gateway}/status/418 -v418 Unknownis returned.Run the following command to access the
/status/403path of the HTTPBin application:curl http://${IP address of the ASM gateway}/status/403 -v403 Forbiddenis returned.Run the following command to access the
/headerspath of the HTTPBin application:curl http://${IP address of the ASM gateway}/headers -H test-header:test-value -vThe response contains the headers carried in the request.
Related operations
You can also deploy the sleep service in the cluster on the data plane and use the sleep service to access the HTTPBin application to verify that the HTTPBin application is deployed successfully.
Use the following content to create a sleep.yaml file:
################################################################################################## # Sample sleep service ################################################################################################## apiVersion: v1 kind: ServiceAccount metadata: name: sleep --- apiVersion: v1 kind: Service metadata: name: sleep labels: app: sleep service: sleep spec: ports: - port: 80 name: http selector: app: sleep --- apiVersion: apps/v1 kind: Deployment metadata: name: sleep spec: replicas: 1 selector: matchLabels: app: sleep template: metadata: labels: app: sleep spec: terminationGracePeriodSeconds: 0 serviceAccountName: sleep containers: - name: sleep image: registry.cn-hangzhou.aliyuncs.com/acs/curl:8.1.2 command: ["/bin/sleep", "infinity"] imagePullPolicy: IfNotPresent volumeMounts: - mountPath: /etc/sleep/tls name: secret-volume volumes: - name: secret-volume secret: secretName: sleep-secret optional: true ---Run the following command to create the sleep service:
kubectl apply -f sleep.yaml -n defaultRun the following command to go to the
shellterminal of the sleep pod:kubectl exec -it deploy/sleep -- shRun the following command to send a request to the HTTPBin application:
curl -I http://httpbin:8000/headersExpected output:
HTTP/1.1 200 OK server: envoy date: Tue, 26 Dec 2023 07:23:49 GMT content-type: application/json content-length: 353 access-control-allow-origin: * access-control-allow-credentials: true x-envoy-upstream-service-time: 1200 OK is returned, which indicates that the access is successful. The HTTPBin application is deployed successfully.