日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

部署httpbin應用

httpbin是一個用于測試的開源應用,常用于Web調試。部署該應用后,您可以方便地查看HTTP請求的Method、Header和授權等信息。本文介紹如何部署httpbin應用。

前提條件

操作步驟

  1. 在數據面集群中部署httpbin應用。

    1. 使用以下內容,創(chuàng)建httpbin-application.yaml

      展開查看httpbin-application.yaml

      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: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/httpbin:0.1.0
              imagePullPolicy: IfNotPresent
              name: httpbin
              ports:
              - containerPort: 80
    2. 使用kubectl連接到ACK集群,執(zhí)行以下命令,部署httpbin應用。

      kubectl apply -f httpbin-application.yaml
  2. 配置httpbin應用的流量規(guī)則。

    1. 使用以下內容,創(chuàng)建網關規(guī)則。具體操作,請參見管理網關規(guī)則

      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. 使用以下內容,創(chuàng)建虛擬服務。具體操作,請參見管理虛擬服務

      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. 進行訪問測試。

    請將下文命令中的${ASM網關IP}替換為實際的網關地址。關于如何獲取網關地址,請參見獲取入口網關地址

    1. 執(zhí)行以下命令,訪問httpbin的/status/200

      curl http://${ASM網關IP}/status/200 -v

      返回200 OK

    2. 執(zhí)行以下命令,訪問httpbin的/status/418

      curl http://${ASM網關IP}/status/418 -v

      返回418 Unknown

    3. 執(zhí)行以下命令,訪問httpbin的/status/403

      curl http://${ASM網關IP}/status/403 -v

      返回403 Forbidden

    4. 執(zhí)行以下命令,訪問httpbin的/headers

      curl http://${ASM網關IP}/headers -H test-header:test-value  -v

      Response會返回請求中攜帶的Header。

相關操作

您也可以通過在數據面集群部署sleep服務,并通過sleep服務去訪問httpbin服務來驗證httpbin服務已經部署成功。

  1. 使用以下內容,創(chuàng)建sleep.yaml。

    ##################################################################################################
    # 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
    ---
  2. 執(zhí)行以下命令,創(chuàng)建sleep應用。

    kubectl apply -f sleep.yaml -n default
  3. 執(zhí)行以下命令,進入sleep Pod的sh終端。

    kubectl exec -it deploy/sleep -- sh
  4. 執(zhí)行以下命令,向httpbin服務發(fā)送請求。

    curl -I http://httpbin:8000/headers

    預期輸出:

    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: 1

    返回200 OK,表明訪問成功。httpbin服務已經正常部署。