내보낸 서비스 구성 항목 참조

내보낸 서비스 구성 항목 참조 (Exported Services Configuration Entry Reference)

이 주제는 exported-services 구성 항목 유형을 설명해요. exported-services 구성 항목을 사용하면 단일 파일에서 서비스 인스턴스를 다른 클러스터로 내보내고 클러스터 간에 서비스를 연결할 수 있어요. 추가 정보는 Cluster Peering 및 Admin Partitions을 참고해요.

출처: 문서

본문

소개 (Introduction)

Consul Enterprise admin partition 또는 Consul CE 데이터 센터에 포함된 서비스를 하나 이상의 추가 클러스터로 내보내도록 Consul을 구성하려면 새 구성 항목을 만들고 kind 필드에 exported-services를 선언해요. 이 구성 항목을 사용하면 서로 다른 클러스터의 서비스 간에 트래픽을 라우팅할 수 있어요.

exported-services 구성 항목에 정의된 설정을 Consul Enterprise admin partition의 모든 네임스페이스에 적용하도록 구성할 수 있어요.

요구 사항 (Requirements)

  • 엔터프라이즈 전용 (Enterprise Only) : 구성 항목이 내보낼 수 있는 해당 파티션. 예를 들어 frontend라는 파티션에 대한 exported-services 구성 항목에는 기존의 frontend 파티션이 필요해요.

사용법 (Usage)

  1. 데이터 센터가 요구 사항에 지정된 조건을 충족하는지 확인해요.
  2. 구성에 설명된 대로 에이전트 구성 파일(config_entries 참조)에 exported-services 구성을 지정해요.
  3. 다음 방법 중 하나를 사용해 구성을 적용해요:

구성 (Configuration)

exported-services 구성 항목을 정의하려면 다음 매개변수를 구성해요.

Consul CE — 내보낸 서비스 구성 구문:

HCL:

Kind = "exported-services"
Name = "default"
Services = [
  {
    Name = "<name of service to export>"
    Consumers = [
      {
        Peer = "<name of the peered cluster that dials the exported service>"
      }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: default
spec:
  services:
    - name: <name of service to export>
      consumers:
        - peer: <name of the peered cluster that dials the exported service>

JSON:

{
  "Kind": "exported-services",
  "Name": "default",
  "Services": [
    {
      "Name": "<name of service to export>",
      "Consumers": [
        {
          "Peer": "<name of the peered cluster that dials the exported service>"
        }
      ]
    }
  ]
}

Consul Enterprise (Peers) — 내보낸 서비스 구성 구문:

HCL:

Kind = "exported-services"
Partition = "<partition containing services to export>"
Name = "<partition containing services to export>"
Services = [
  {
    Name = "<name of service to export>"
    Namespace = "<namespace in the partition containing the service to export>"
    Consumers = [
      {
        Peer = "<name of the peered cluster that dials the exported service>"
      }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: <partition containing services to export>
spec:
  services:
    - name: <name of service to export>
      namespace: <namespace in the partition containing the service to export>
      consumers:
        - peer: <name of the peered cluster that dials the exported service>

JSON:

{
  "Kind": "exported-services",
  "Partition": "<partition containing services to export>",
  "Name": "<partition containing services to export>",
  "Services": [
    {
      "Name": "<name of service to export>",
      "Namespace": "<namespace in the partition containing the service to export>",
      "Consumers": [
        {
          "Peer": "<name of the peered cluster that dials the exported service>"
        }
      ]
    }
  ]
}

Consul Enterprise (Partitions) — 내보낸 서비스 구성 구문:

HCL:

Kind = "exported-services"
Partition = "<partition containing services to export>"
Name = "<partition containing services to export>"
Services = [
  {
    Name = "<name of service to export>"
    Namespace = "<namespace in the partition containing the service to export>"
    Consumers = [
      {
        Partition = "<name of the partition that dials the exported service>"
      }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: <partition containing services to export>
spec:
  services:
    - name: <name of service to export>
      namespace: <namespace in the partition containing the service to export>
      consumers:
        - partition: <name of the partition that dials the exported service>

JSON:

{
  "Kind": "exported-services",
  "Partition": "<partition containing services to export>",
  "Name": "<partition containing services to export>",
  "Services": [
    {
      "Name": "<name of service to export>",
      "Namespace": "<namespace in the partition containing the service to export>",
      "Consumers": [
        {
          "Partition": "<name of partition that dials the exported service>"
        }
      ]
    }
  ]
}

Consul Enterprise (Sameness Group) — 내보낸 서비스 구성 구문:

HCL:

Kind = "exported-services"
Partition = "<partition containing services to export>"
Name = "<partition containing services to export>"
Services = [
  {
    Name = "<name of service to export>"
    Namespace = "<namespace in the partition containing the service to export>"
    Consumers = [
      {
        SamenessGroup = "<name of the sameness group that dials the exported service>"
      }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: <partition containing services to export>
spec:
  services:
    - name: <name of service to export>
      namespace: <namespace in the partition containing the service to export>
      consumers:
        - samenessGroup: <name of the sameness group that dials the exported service>

JSON:

{
  "Kind": "exported-services",
  "Partition": "<partition containing services to export>",
  "Name": "<partition containing services to export>",
  "Services": [
    {
      "Name": "<name of service to export>",
      "Namespace": "<namespace in the partition containing the service to export>",
      "Consumers": [
        {
          "SamenessGroup": "<name of the sameness group that dials the exported service>"
        }
      ]
    }
  ]
}

구성 매개변수 (Configuration Parameters)

다음 표는 exported-services 구성 항목과 관련된 매개변수를 설명해요.

매개변수 설명 필수 기본값
Kind 구성 항목을 활성화하는 문자열 값. 값은 항상 exported-services(HCL 및 JSON) 또는 ExportedServices(YAML)여야 해요. 필수 없음
Partition Enterprise 내보내려는 서비스가 포함된 파티션의 이름을 지정하는 문자열 값. 필수 없음
Name 내보내려는 서비스가 포함된 파티션의 이름을 지정하는 문자열 값. Consul CE에서는 default여야 해요. 필수 없음
Services 내보낼 서비스를 지정하는 객체 목록. 자세한 내용은 Services를 참고해요. 필수 없음
Meta 최대 64개의 키/값 쌍 맵을 정의하는 객체. 선택 없음

Services

Services 매개변수는 내보낼 서비스, 서비스가 위치한 네임스페이스, 내보낸 서비스의 대상 클러스터를 지정하는 하나 이상의 매개변수 목록을 포함해요. Services 목록의 각 항목은 다음 매개변수를 포함해야 해요:

  • Name: 내보낼 서비스의 이름을 지정해요. 별표 와일드카드(*)를 사용해 네임스페이스의 모든 서비스를 포함할 수 있어요.
  • Namespace: \n\nEnterprise\n\n내보낼 서비스가 포함된 네임스페이스를 지정해요. 별표 와일드카드(*)를 사용해 파티션의 모든 네임스페이스를 포함할 수 있어요.
  • Consumers: 내보낸 서비스의 대상 클러스터를 식별하는 하나 이상의 객체를 지정해요.

Consumers

Consumers 매개변수는 내보낸 서비스의 대상 클러스터를 지정하는 하나 이상의 매개변수 목록을 포함해요. Consumers 목록의 각 항목은 다음 매개변수 중 정확히 하나를 포함해야 해요:

  • Peer: 서비스를 내보낼 피어링된 클러스터의 이름을 지정해요. Peer로 별표 와일드카드(*)를 지정할 수 없어요. Consul 1.13.0에 추가됨.
  • Partition: \n\nEnterprise\n\n서비스를 내보낼 데이터 센터의 admin partition을 지정해요. Partition으로 별표 와일드카드(*)를 지정할 수 없어요.
  • SamenessGroup: \n\nEnterprise\n\n서비스를 내보낼 sameness group을 지정해요. SamenessGroup으로 별표 와일드카드(*)를 지정할 수 없어요.

예시 (Examples)

피어링된 클러스터로 서비스 내보내기 (Exporting services to peered clusters)

Consul CE — 다음 예시는 payments 및 refunds 서비스를 피어링된 web-shop 클러스터로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Name = "default"

Services = [
  {
    Name      = "payments"
    Consumers = [
        {
            Peer  = "web-shop"
        },
    ]
  },
  {
    Name      = "refunds"
    Consumers = [
        {
            Peer = "web-shop"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: default
spec:
  services:
    - name: payments
      consumers:
        - peer: web-shop
    - name: refunds
      consumers:
        - peer: web-shop

JSON:

{
  "Kind": "exported-services",
  "Name": "default",
  "Services": [
    {
      "Name": "payments",
      "Consumers": [
        {
          "Peer": "web-shop"
        }
      ]
    },
    {
      "Name": "refunds",
      "Consumers": [
        {
          "Peer": "web-shop"
        }
      ]
    }
  ]
}

Consul Enterprise (Peers) — 다음 예시는 finance admin partition의 billing 네임스페이스에서 payments 및 refunds 서비스를 web-shop 피어로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Partition = "finance"
Name = "finance"

Services = [
  {
    Name      = "payments"
    Namespace = "billing"
    Consumers = [
        {
            Peer  = "web-shop"
        },
    ]
  },
  {
    Name      = "refunds"
    Namespace = "billing"
    Consumers = [
        {
            Peer = "web-shop"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: finance
spec:
  services:
    - name: payments
      namespace: billing
      consumers:
        - peer: web-shop
    - name: refunds
      namespace: billing
      consumers:
        - peer: web-shop

JSON:

{
  "Kind": "exported-services",
  "Partition": "finance",
  "Name": "finance",
  "Services": [
    {
      "Name": "payments",
      "Namespace": "billing",
      "Consumers": [
        {
          "Peer": "web-shop"
        }
      ]
    },
    {
      "Name": "refunds",
      "Namespace": "billing",
      "Consumers": [
        {
          "Peer": "web-shop"
        }
      ]
    }
  ]
}

Consul Enterprise (Partitions) — 다음 예시는 finance admin partition의 billing 네임스페이스에서 payments 및 refunds 서비스를 web-shop 파티션으로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Partition = "finance"
Name = "finance"

Services = [
  {
    Name      = "payments"
    Namespace = "billing"
    Consumers = [
        {
            Partition  = "web-shop"
        }
    ]
  },
  {
    Name      = "refunds"
    Namespace = "billing"
    Consumers = [
        {
            Partition = "web-shop"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: finance
spec:
  services:
    - name: payments
      namespace: billing
      consumers:
        - partition: web-shop
    - name: refunds
      namespace: billing
      consumers:
        - partition: web-shop

JSON:

{
  "Kind": "exported-services",
  "Partition": "finance",
  "Name": "finance",
  "Services": [
    {
      "Name": "payments",
      "Namespace": "billing",
      "Consumers": [
        {
          "Partition": "web-shop"
        }
      ]
    },
    {
      "Name": "refunds",
      "Namespace": "billing",
      "Consumers": [
        {
          "Partition": "web-shop"
        }
      ]
    }
  ]
}

sameness group으로 서비스 내보내기 (Exporting a service to a sameness group)

다음 예시는 api라는 서비스를 별도로 정의된 sameness group인 monitoring에 속한 파티션 그룹으로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Name = "default"

Services = [
  {
    Name      = "api"
    Consumers = [
        {
            SamenessGroup  = "monitoring"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: default
spec:
  services:
    - name: api
      consumers:
        - samenessGroup: monitoring

JSON:

{
  "Kind": "exported-services",
  "Name": "default",
  "Services": [
    {
      "Name": "api",
      "Consumers": [
        {
          "SamenessGroup": "monitoring"
        }
      ]
    }
  ]
}

모든 서비스 내보내기 (Exporting all services)

Consul CE — 다음 예시는 데이터 센터의 모든 서비스를 피어링된 monitoring 및 platform 클러스터로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Name = "default"

Services = [
  {
    Name      = "*"
    Consumers = [
        {
            Peer  = "monitoring"
        },
        {
            Peer  = "platform"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: default
spec:
  services:
    - name: *
      consumers:
        - peer: monitoring
        - peer: platform

JSON:

{
  "Kind": "exported-services",
  "Name": "default",
  "Services": [
    {
      "Name": "*",
      "Namespace": "*",
      "Consumers": [
        {
          "Peer": "monitoring"
        },
        {
          "Peer": "platform"
        }
      ]
    }
  ]
}

Consul Enterprise (Peers) — 다음 예시는 finance 파티션의 모든 네임스페이스의 모든 서비스를 피어링된 monitoring 및 platform 클러스터로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Partition = "finance"
Name = "finance"

Services = [
  {
    Name      = "*"
    Namespace = "*"
    Consumers = [
        {
            Peer = "monitoring"
        },
        {
            Peer = "platform"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: finance
spec:
  services:
    - name: *
      namespace: *
      consumers:
        - peer: monitoring
        - peer: platform

JSON:

{
  "Kind": "exported-services",
  "Partition": "finance",
  "Name": "finance",
  "Services": [
    {
      "Name": "*",
      "Namespace": "*",
      "Consumers": [
        {
          "Peer": "monitoring"
        },
        {
          "Peer": "platform"
        }
      ]
    }
  ]
}

Consul Enterprise (Partitions) — 다음 예시는 finance 파티션의 모든 네임스페이스의 모든 서비스를 monitoring 및 platform 파티션으로 내보내도록 Consul을 구성해요.

HCL:

Kind = "exported-services"
Partition = "finance"
Name = "finance"

Services = [
  {
    Name      = "*"
    Namespace = "*"
    Consumers = [
        {
            Partition = "monitoring"
        },
        {
            Partition = "platform"
        }
    ]
  }
]

Kubernetes YAML:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ExportedServices
metadata:
  name: finance
spec:
  services:
    - name: *
      namespace: *
      consumers:
        - partition: monitoring
        - partition: platform

JSON:

{
  "Kind": "exported-services",
  "Partition": "finance",
  "Name": "finance",
  "Services": [
    {
      "Name": "*",
      "Namespace": "*",
      "Consumers": [
        {
          "Partition": "monitoring"
        },
        {
          "Partition": "platform"
        }
      ]
    }
  ]
}

Consul on Kubernetes에서 와일드카드를 사용해 서비스를 내보낼 때 오류가 발생하면 서비스 토큰이 모든 네임스페이스에 대한 읽기 접근을 부여하는 정책에 연결되어 있는지 확인해요:

partition "default" {
  namespace "default" {
    query_prefix "" {
      policy = "read"
    }
  }
}

partition_prefix "" {
  namespace_prefix "" {
    node_prefix "" {
      policy = "read"
    }
    service_prefix "" {
      policy = "read"
    }
   }
}

서비스 읽기 (Reading Services)

내보낸 서비스가 다른 클러스터로 가져와지면 health REST API 엔드포인트를 사용해 소비자 클러스터에서 서비스를 쿼리할 수 있어요.

Consul CE — 다음 예시는 finance 피어에서 가져온 payments 서비스를 쿼리해요:

$ curl 'localhost:8500/v1/health/service/payments?peer=finance'

쿼리가 이루어지는 클러스터에서는 다음 권한 중 하나가 있는 ACL 토큰이 필요해요:

  • 모든 서비스에 대한 service:write 권한.
  • 모든 서비스 및 노드에 대한 service:read 및 node:read 권한(각각).

이전 예시의 호출이 web이라는 서비스에서 이루어지는 경우 요청에는 다음 중 하나가 필요해요:

  • web에 대한 service:write 권한이 있는 토큰.
  • 데이터 센터의 모든 이름에 대한 service:read 및 node:read가 있는 토큰.

Consul CE에서 가져온 서비스를 읽기 위한 ACL 규칙 예시 — HCL:

service "web" {
    policy = "write"
}

# OR

service_prefix "" {
    policy = "read"
}
node_prefix "" {
    policy = "read"
}

JSON:

{
  "service": {
    "web": {
      "policy": "write"
    }
  }
}

## OR

{
  "service_prefix": {
    "": {
      "policy": "read"
    }
  },
  "node_prefix": {
    "": {
      "policy": "read"
    }
  }
}

Consul Enterprise (Partitions) — 다음 예시는 finance 파티션에서 가져온 payments 서비스를 쿼리해요:

$ curl 'localhost:8500/v1/health/service/payments?partition=finance'

쿼리가 이루어지는 클러스터에서는 다음 권한 중 하나가 있는 ACL 토큰이 필요해요:

  • 쿼리가 이루어지는 파티션의 모든 서비스에 대한 service:write 권한.
  • 쿼리가 이루어지는 정확한 파티션의 모든 네임스페이스에서 모든 서비스 및 노드에 대한 service:read 및 node:read 권한(각각).

이전 예시의 호출이 frontend라는 파티션의 web이라는 서비스에서 이루어지는 경우 요청에는 다음 중 하나가 필요해요:

  • frontend 파티션의 web에 대한 service:write 권한이 있는 토큰.
  • 모든 네임스페이스에 대해 frontend 파티션의 모든 이름에 대한 service:read 및 node:read가 있는 토큰.

Consul Enterprise에서 파티션에서 가져온 서비스를 읽기 위한 ACL 규칙 예시 — HCL:

partition "frontend" {
    namespace "dev" { # This could be any namespace
        service "web" {
            policy = "write"
        }
    }
}

# OR

partition "frontend" {
    namespace "dev" { # This could be any namespace
        service_prefix "" {
            policy = "read"
        }
        node_prefix "" {
            policy = "read"
        }
    }
}

JSON:

{
  "partition": {
    "frontend": {
      "namespace": {
        ## The following could be any namespace
        "dev": {
          "service": {
            "web": {
              "policy": "write"
            }
          }
        }
      }
    }
  }
}

## OR

{
  "partition": {
    "frontend": {
      "namespace": {
        ## The following could be any namespace
        "dev": {
          "service_prefix": {
            "": {
              "policy": "read"
            }
          },
          "node_prefix": {
            "": {
              "policy": "read"
            }
          }
        }
      }
    }
  }
}

Consul Enterprise (Peers) — 다음 예시는 finance 피어에서 가져온 payments 서비스를 쿼리해요:

$ curl 'localhost:8500/v1/health/service/payments?peer=finance'

쿼리가 이루어지는 클러스터에서는 다음 권한 중 하나가 있는 ACL 토큰이 필요해요:

  • 쿼리가 이루어지는 파티션의 모든 서비스에 대한 service:write 권한.
  • 쿼리가 이루어지는 정확한 파티션의 모든 네임스페이스에서 모든 서비스 및 노드에 대한 service:read 및 node:read 권한(각각).

이전 예시의 호출이 frontend라는 파티션의 web이라는 서비스에서 이루어지는 경우 요청에는 다음 중 하나가 필요해요:

  • frontend 파티션의 web에 대한 service:write 권한이 있는 토큰.
  • 모든 네임스페이스에 대해 frontend 파티션의 모든 이름에 대한 service:read 및 node:read가 있는 토큰.

Consul Enterprise에서 피어에서 가져온 서비스를 읽기 위한 ACL 규칙 예시 — HCL:

partition "frontend" {
    namespace "dev" { # This could be any namespace
        service "web" {
            policy = "write"
        }
    }
}

# OR

partition "frontend" {
    namespace "dev" { # This could be any namespace
        service_prefix "" {
            policy = "read"
        }
        node_prefix "" {
            policy = "read"
        }
    }
}

JSON:

{
  "partition": {
    "frontend": {
      "namespace": {
        ## The following could be any namespace
        "dev": {
          "service": {
            "web": {
              "policy": "write"
            }
          }
        }
      }
    }
  }
}

## OR

{
  "partition": {
    "frontend": {
      "namespace": {
        ## The following could be any namespace
        "dev": {
          "service_prefix": {
            "": {
              "policy": "read"
            }
          },
          "node_prefix": {
            "": {
              "policy": "read"
            }
          }
        }
      }
    }
  }
}

추가 정보는 Health HTTP Endpoint를 참고해요.

더 알아보기 (Learn more)