すべてのプロダクト
Search
ドキュメントセンター

:準備

最終更新日:Jan 15, 2025

レイヤー7ルーティングは、URIパスの一致やリクエストヘッダーの一致など、複数の機能をサポートしています。このトピックでは、レイヤー7ルーティング関連の機能を実装するための準備について説明します。

前提条件

  • Enterprise Edition の Service Mesh(ASM)インスタンスが作成されていること。詳細については、「ASM インスタンスの作成」をご参照ください。

    [データプレーンモード] セクションの [サービスメッシュの作成] ページで、[アンビエントメッシュモードを有効にする] を選択しないでください。

  • Container Service for Kubernetes(ACK)クラスターが作成されていること。クラスターの作成方法の詳細については、「ACK 専用クラスターの作成」または「ACK マネージドクラスターの作成」をご参照ください。

  • クラスターが ASM インスタンスに追加されていること。詳細については、「ASM インスタンスへのクラスターの追加」をご参照ください。

  • デフォルトの名前空間でサイドカープロキシの自動インジェクションが有効になっていること。詳細については、「グローバル名前空間の管理」トピックの「サイドカープロキシの自動インジェクションを有効にする」セクションをご参照ください。

手順

ビジネス要件に基づいて、ACK クラスターに helloworld、sleep、HTTPBin、または NGINX サービスをデプロイします。

helloworld サービスのデプロイ

  1. 以下の内容を使用して、helloworld-application.yaml ファイルを作成します。

    [helloworld-application.yaml ファイルを表示するには展開します]

    apiVersion: v1
    kind: Service
    metadata:
      name: helloworld
      labels:
        app: helloworld
    spec:
      ports:
      - port: 5000
        name: http
      selector:
        app: helloworld
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: helloworld
      labels:
        account: helloworld
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: helloworld-v1
      labels: 
        apps: helloworld
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: helloworld
          version: v1
      template:
        metadata:
          labels:
            app: helloworld
            version: v1
        spec:
          serviceAccount: helloworld
          serviceAccountName: helloworld
          containers:
          - name: helloworld
            image: istio/examples-helloworld-v1
            imagePullPolicy: IfNotPresent 
            ports:
            - containerPort: 5000
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: helloworld-v2
      labels: 
        apps: helloworld
        version: v2
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: helloworld
          version: v2
      template:
        metadata:
          labels:
            app: helloworld
            version: v2
        spec:
          serviceAccount: helloworld
          serviceAccountName: helloworld
          containers:
          - name: helloworld
            image: istio/examples-helloworld-v2
            imagePullPolicy: IfNotPresent 
            ports:
            - containerPort: 5000
  2. kubeconfig ファイルの情報に基づいて kubectl を使用して ACK クラスターに接続し、次のコマンドを実行して helloworld サービスをデプロイします。

    kubectl apply -f helloworld-application.yaml

sleep サービスのデプロイ

  1. 以下の内容を使用して、sleep-application.yaml ファイルを作成します。

    [sleep-application.yaml ファイルを表示するには展開します]

    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: curlimages/curl
            command: ["/bin/sleep", "3650d"]
            imagePullPolicy: IfNotPresent
            volumeMounts:
            - mountPath: /etc/sleep/tls
              name: secret-volume
          volumes:
          - name: secret-volume
            secret:
              secretName: sleep-secret
              optional: true
  2. kubeconfig ファイルの情報に基づいて kubectl を使用して ACK クラスターに接続し、次のコマンドを実行して sleep サービスをデプロイします。

    kubectl apply -f sleep-application.yaml

HTTPBin サービスのデプロイ

  1. 以下の内容を使用して、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: docker.io/kennethreitz/httpbin
            imagePullPolicy: IfNotPresent
            name: httpbin
            ports:
            - containerPort: 80
  2. kubeconfig ファイルの情報に基づいて kubectl を使用して ACK クラスターに接続し、次のコマンドを実行して HTTPBin サービスをデプロイします。

    kubectl apply -f httpbin-application.yaml

NGINX サービスのデプロイ

  1. 以下の内容を使用して、nginx.yaml ファイルを作成します。

    [nginx.yaml ファイルを表示するには展開します]

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: nginx
    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: nginx
        service: nginx
      name: nginx
    spec:
      ports:
        - name: http
          port: 8000
          protocol: TCP
          targetPort: 80
      selector:
        app: nginx
      type: ClusterIP
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: nginx
        version: v1
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
          version: v1
      template:
        metadata:
          labels:
            app: nginx
            version: v1
        spec:
          serviceAccountName: nginx
          containers:
            - image: 'nginx:1.7.9'
              name: nginx
              ports:
                - containerPort: 80
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
  2. kubeconfig ファイルの情報に基づいて kubectl を使用して ACK クラスターに接続し、次のコマンドを実行して NGINX サービスをデプロイします。

    kubectl apply -f nginx.yaml