Istio
Istio는 웹 서비스로 흐르는 트래픽을 제어하는 풍부한 기능을 제공하는 서비스 메시예요.
출처: 문서
본문
Istio는 웹 서비스로 흐르는 트래픽을 제어하는 풍부한 기능을 제공하는 서비스 메시예요. Istio는 CRD 집합을 통해 이 기능을 제공하고, Argo Rollouts은 이 리소스들의 관리를 자동화해서 업데이트 중에 Rollout의 서로 다른 버전에게 고급 트래픽 셰이핑 기능을 제공해요.
동작 방식 (How it works)
Istio에서 트래픽 분할은 Istio VirtualService에 정의된 트래픽 weight를 조정해서 이뤄져요. Argo Rollouts을 Istio와 함께 쓸 때, 사용자는 최소한 하나의 HTTP route와 두 개의 HTTP route destination이 있는 VirtualService를 배포해요. 하나는 카나리아 ReplicaSet의 파드를 타깃으로 하고, 다른 하나는 안정(Stable) ReplicaSet의 파드를 타깃으로 해요. Istio는 가중치 기반 트래픽 분할에 두 가지 접근 방식을 제공하는데, 둘 다 Argo Rollouts에서 옵션으로 사용할 수 있어요.
- 호스트 수준 트래픽 분할 (Host-level traffic splitting)
- 서브셋 수준 트래픽 분할 (Subset-level traffic splitting)
참고 (Note)
Istio를 사용할 때 서비스 메시 안에 있는 트래픽만 롤아웃 전략을 따르게 돼요. 서비스 메시에서 제외된 파드(예: sidecar.istio.io/inject="false" 라벨 때문)는 기본 Kubernetes 트래픽 라우팅을 따르게 돼요.
호스트 수준 트래픽 분할 (Host-level Traffic Splitting)
Argo Rollouts과 Istio를 사용하는 첫 번째 트래픽 분할 접근 방식은 두 호스트명, 즉 두 Kubernetes Service(카나리아 Service와 안정 Service) 사이에서 분할하는 거예요. 이 접근 방식은 다른 모든 Argo Rollouts mesh/ingress-controller 통합(예: ALB, SMI, Nginx)과 비슷해요. 이 접근 방식을 사용하면 사용자는 다음 리소스를 배포해야 해요.
- Rollout
- Service (canary)
- Service (stable)
- VirtualService
Rollout은 다음 필드를 정의해야 해요.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-example
spec:
...
strategy:
canary:
canaryService: canary-svc # required
stableService: stable-svc # required
trafficRouting:
istio:
virtualService:
name: rollout-vsvc # required
routes:
- primary # optional if there is a single route in VirtualService, required otherwise
steps:
- setWeight: 5
- pause:
duration: 10m
VirtualService에는 Rollout에서 참조된 이름의 HTTP route가 있어야 하고, Rollout에서 참조된 canaryService와 stableService와 일치하는 host 값의 두 route destination이 있어야 해요. VirtualService가 rollout과 다른 네임스페이스에 정의되어 있다면, 그 이름은 rollout-vsvc.<vsvc namespace name>이어야 해요. Istio는 모든 weight의 합이 100이어야 하므로, 초기 weight는 안정에 100%, 카나리아에 0%로 할 수 있어요.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rollout-vsvc
spec:
gateways:
- istio-rollout-gateway
hosts:
- istio-rollout.dev.argoproj.io
http:
- name: primary # referenced in canary.trafficRouting.istio.virtualService.routes
route:
- destination:
host: stable-svc # referenced in canary.stableService
weight: 100
- destination:
host: canary-svc # referenced in canary.canaryService
weight: 0
마지막으로 canary와 stable Service를 배포해야 해요. 이 Service들의 selector는 업데이트 중에 Rollout이 canary·stable ReplicaSet 파드를 타깃으로 하도록 수정돼요. VirtualService와 destination host가 서로 다른 네임스페이스에 있다면(예: VirtualService와 Rollout이 같은 네임스페이스가 아닌 경우), destination host에 네임스페이스를 포함해야 해요(예: stable-svc.<namespace>).
apiVersion: v1
kind: Service
metadata:
name: canary-svc
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo
# This selector will be updated with the pod-template-hash of the canary ReplicaSet. e.g.:
# rollouts-pod-template-hash: 7bf84f9696
---
apiVersion: v1
kind: Service
metadata:
name: stable-svc
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo
# This selector will be updated with the pod-template-hash of the stable ReplicaSet. e.g.:
# rollouts-pod-template-hash: 123746c88d
Rollout 업데이트의 수명 주기 동안 Argo Rollouts은 지속적으로 다음을 수행해요.
- canary Service
spec.selector를 카나리아 ReplicaSet의rollouts-pod-template-hash라벨을 포함하도록 수정 - stable Service
spec.selector를 안정 ReplicaSet의rollouts-pod-template-hash라벨을 포함하도록 수정 - VirtualService
spec.http[].route[].weight를 현재 원하는 카나리아 weight와 일치하도록 수정
참고 (Note)
Rollout은 VirtualService나 Istio mesh 내의 다른 필드에 대해 어떤 가정도 하지 않아요. 사용자는 primary route나 다른 route에 URI rewrite 규칙 같은 VirtualService 추가 구성을 지정할 수 있어요. 각 service에 대한 특정 DestinationRule도 만들 수 있어요.
서브셋 수준 트래픽 분할 (Subset-level Traffic Splitting)
중요 (Important)
v1.0부터 사용 가능해요.
Argo Rollouts과 Istio를 사용하는 두 번째 트래픽 분할 접근 방식은 두 Istio DestinationRule Subset(카나리아 subset과 안정 subset) 사이에서 분할하는 거예요. 사용자는 트래픽을 보낼 추가 subset DestinationRule도 지정할 수 있어요. DestinationRule subset으로 분할할 때 사용자는 다음 리소스를 배포해야 해요.
- Rollout
- Service
- VirtualService
- DestinationRule
Rollout은 다음 필드를 정의해야 해요.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-example
spec:
...
strategy:
canary:
trafficRouting:
istio:
virtualService:
name: rollout-vsvc # required
routes:
- primary # optional if there is a single route in VirtualService, required otherwise
destinationRule:
name: rollout-destrule # required
canarySubsetName: canary # required
stableSubsetName: stable # required
steps:
- setWeight: 5
- pause:
duration: 10m
단일 service를 정의해야 하며, 이 service는 Rollout 파드를 타깃으로 해요. 첫 번째 접근 방식처럼 트래픽 분할이 canary/stable ReplicaSet의 rollout-pod-template-hash를 포함하도록 수정된 여러 Service 사이에서 이뤄지는 것과 달리, 이 Service는 rollout 컨트롤러에 의해 수정되지 않아요.
apiVersion: v1
kind: Service
metadata:
name: rollout-example
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollout-example
VirtualService에는 Rollout에서 참조된 이름의 HTTP route가 있어야 하고, Rollout에서 참조된 canarySubsetName과 stableSubsetName과 일치하는 subset 값의 두 route destination이 있어야 해요. Istio는 모든 weight의 합이 100이어야 하므로, 초기 weight는 안정에 100%, 카나리아에 0%로 할 수 있어요.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rollout-vsvc
spec:
gateways:
- istio-rollout-gateway
hosts:
- istio-rollout.dev.argoproj.io
http:
- name: primary # referenced in canary.trafficRouting.istio.virtualService.routes
route:
- destination:
host: rollout-example
subset: stable # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
weight: 100
- destination:
host: rollout-example
subset: canary # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
weight: 0
마지막으로 Rollout에서 참조된 canary·stable subset을 포함하는 DestinationRule을 배포해요.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: rollout-destrule
spec:
host: rollout-example
subsets:
- name: canary # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
labels: # labels will be injected with canary rollouts-pod-template-hash value
app: rollout-example
- name: stable # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
labels: # labels will be injected with stable rollouts-pod-template-hash value
app: rollout-example
Istio DestinationRule을 사용하는 Rollout의 수명 주기 동안 Argo Rollouts은 지속적으로 다음을 수행해요.
- VirtualService
spec.http[].route[].weight를 현재 원하는 카나리아 weight와 일치하도록 수정 - DestinationRule
spec.subsets[].labels를 canary·stable ReplicaSet의rollouts-pod-template-hash라벨을 포함하도록 수정
추가 Subset DestinationRule
Argo Rollouts은 사용자가 추가 subset DestinationRule을 만들 수도 있게 해요. 한 가지 쓰임새는 API의 경로(예: /api/mypath)로 제공되는 추가 트래픽을 Argo Rollouts이 처리하는 service(안정·카나리아 DestinationRule 포함)와 실험 이미지를 사용하는 service로 보내는 거예요.
예를 들어 다음과 같은 subset을 가질 수 있어요.
canary- 테스트 중인 새 버전stable- 현재 프로덕션 버전legacy- 하위 호환을 위한 이전 버전experimental- 실험 기능이 있는 버전
이 기능을 활성화하려면 일반 subset DestinationRule 배포의 위 단계를 따르세요. 그런 다음 canary·subset DestinationRule을 포함하는 VirtualService를 수정해서 추가 subset 이름과 원하는 트래픽 weight를 포함시켜요.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rollout-vsvc
spec:
...
http:
- name: primary
route:
- destination:
host: rollout-example # same as the steps above
subset: stable
weight: 100 # you can leave this as 100, Argo Rollouts will handle the adjusted total weight so that the weights add up to 100%
- destination:
host: rollout-example
subset: canary
weight: 0
- destination:
host: experiment-host # this references the host of the additional Service (or whatever is configured by the additional Service)
subset: experiment # new and additional subset DestinationRule, referencing the spec.subsets.name of the DestinationRule
weight: 20
추가 DestinationRule(그리고 그것이 의존하는 Service, Deployment 등)도 적절한 spec.host, spec.subsets.name, spec.subsets.labels.app 필드와 함께 배포해야 해요.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: experimental-destrule
spec:
host: experimental-host
exportTo:
- .
- ingress-system
subsets:
- name: experiment
labels:
app: experimental-host
마지막으로 추가 DestinationRule의 이름을 Rollout spec에 다음과 같이 추가해요.
...
destinationRule:
name: rollout-destrule # required
canarySubsetName: canary # required
stableSubsetName: stable # required
additionalSubsetNames: # not required, optional
... # any other additional DestinationRule's
- "experiment"
Argo Rollouts 컨트롤러는 canary·stable subset 사이의 트래픽 weight를 관리하고, 추가 subset DestinationRule로 보내지는 weight를 안정 트래픽에서 빼요. 예: 안정이 100%에서 시작하지만 추가 DestinationRule이 트래픽 weight의 20%를 차지한다면, 실제로는 80%에서 시작하게 돼요.
TCP 트래픽 분할 (TCP Traffic Splitting)
중요 (Important)
v1.2.2부터 사용 가능해요.
TCP 트래픽 분할 지원이 도입됐고, 이를 위해 Rollout은 다음 필드를 정의해야 해요.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-example
spec:
...
strategy:
canary:
canaryService: canary-svc # required
stableService: stable-svc # required
trafficRouting:
istio:
virtualService:
name: rollout-vsvc # required
tcpRoutes:
# Below fields are optional but if defined, they should match exactly with at least one of the TCP route match rules in your VirtualService
- port: 3000 # Only required if you want to match any rule in your VirtualService which contains this port
steps:
- setWeight: 5
- pause:
duration: 10m
VirtualService에는 Rollout에서 참조된 일치하는 port의 TCP route가 있어야 해요.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rollout-vsvc
spec:
gateways:
- istio-rollout-gateway
hosts:
- istio-rollout.dev.argoproj.io
tcp:
- match:
- port: 3000
route:
- destination:
host: stable-svc # referenced in canary.stableService
weight: 100
- destination:
host: canary-svc # referenced in canary.canaryService
weight: 0
멀티클러스터 설정 (Multicluster Setup)
Istio 멀티클러스터 설정이 있는데 primary Istio 클러스터가 Argo Rollout 컨트롤러가 실행 중인 클러스터와 다르다면, 다음 설정을 해야 해요.
- Istio primary 클러스터에
ServiceAccount를 생성해요.
apiVersion: v1
kind: ServiceAccount
metadata:
name: argo-rollouts-istio-primary
namespace: <any-namespace-preferrably-config-namespace>
- Istio primary 클러스터에서 Rollout 컨트롤러에 대한 접근을 제공하는
ClusterRole을 생성해요.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: argo-rollouts-istio-primary
rules:
- apiGroups:
- networking.istio.io
resources:
- virtualservices
- destinationrules
verbs:
- get
- list
- watch
- update
- patch
참고: Argo Rollout 컨트롤러도 Istio primary 클러스터에 설치되어 있다면, 새로 만들지 않고 argo-rollouts-clusterrole ClusterRole을 재사용할 수 있어요.
- Istio primary 클러스터에서
ClusterRole을ServiceAccount와 연결해요.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: argo-rollouts-istio-primary
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: argo-rollouts-istio-primary
subjects:
- kind: ServiceAccount
name: argo-rollouts-istio-primary
namespace: <namespace-of-the-service-account>
- 이제 Rollout 컨트롤러가 Istio primary 클러스터에 접근하기 위한 secret을 생성하는 다음 명령을 사용해요. 이 secret은 Argo Rollout이 실행 중인 클러스터(즉 Istio remote 클러스터)에 적용되지만, Istio primary 클러스터에서 생성돼요. 이 secret은 Step 1 직후에 생성할 수 있는데,
ServiceAccount만 존재하면 되기 때문이에요. 명령을 참조하세요.
istioctl x create-remote-secret --type remote --name <cluster-name> \
--namespace <namespace-of-the-service-account> \
--service-account <service-account-created-in-step1> \
--context="<ISTIO_PRIMARY_CLUSTER>" | \
kubectl apply -f - --context="<ARGO_ROLLOUT_CLUSTER/ISTIO_REMOTE_CLUSTER>"
- secret에 라벨을 붙여요.
kubectl label secret <istio-remote-secret> istio.argoproj.io/primary-cluster="true" -n <namespace-of-the-secret>
접근 방식 비교 (Comparison Between Approaches)
호스트 수준 트래픽 분할과 서브셋 수준 트래픽 분할에는 각각 장단점이 있어요.
DNS 요구사항 (DNS requirements)
호스트 수준 분할에서는 VirtualService가 두 destination 사이를 분할하기 위해 서로 다른 host 값을 필요로 해요. 하지만 두 host 값을 쓰는 건 서로 다른 DNS 이름(하나는 canary용, 다른 하나는 stable용)을 쓴다는 뜻이에요. Istio Gateway를 통해 Service에 도달하는 north-south 트래픽의 경우, canary·stable 파드에 도달하기 위한 여러 DNS 이름이 있어도 문제없을 수 있어요. 하지만 east-west 또는 클러스터 내 트래픽의 경우, 마이크로서비스 간 통신이 stable DNS 이름을 칠지 canary DNS 이름을 칠지, gateway를 거칠지, VirtualService용 DNS 항목을 추가할지 선택해야 하게 돼요. 이런 상황에서는 클러스터 내 카나리잉을 위해 DestinationRule subset 트래픽 분할이 더 나은 선택이에요.
메트릭 (Metrics)
호스트 수준 분할 vs 서브셋 수준 분할 중 어떤 것을 선택하느냐에 따라 다른 스타일의 prometheus 메트릭을 사용할 수 있어요. 예를 들어 호스트 수준 분할을 쓰면 canary vs stable의 메트릭이 Istio Service metrics 대시보드에 나타나요.
반면 서브셋으로 분할할 때는 workload 이름 같은 다른 매개변수로 prometheus를 쿼리해야 해요.
GitOps와 통합 (Integrating with GitOps)
앞서 VirtualService는 다음과 같은 예시처럼 초기 canary weight 0, stable weight 100으로 배포해야 한다고 설명했어요.
http:
- name: primary
route:
- destination:
host: stable-svc
weight: 100
- destination:
host: canary-svc
weight: 0
이것은 GitOps를 실천하는 사용자에게 문제를 일으켜요. Rollout이 단계를 진행하며 이 VirtualService weight를 수정하므로, VirtualService가 git의 버전과 OutOfSync 상태가 되기 때문이에요. 게다가 Rollout이 이 상태(서비스 사이에서 트래픽을 분할 중)일 때 git의 VirtualService가 적용된다면, 그 apply는 weight를 git의 값(즉 stable 100, canary 0)으로 되돌려 버려요.
Argo Rollouts에 구현된 한 가지 보호 장치는, 관리하는 VirtualService의 변경을 계속 감시한다는 거예요. git의 VirtualService로 kubectl apply가 실행되는 일이 생기면, 그 변경을 rollout 컨트롤러가 즉시 감지하고 VirtualService weight를 Rollout의 해당 단계에 적절한 카나리아 weight로 즉시 되돌려요. 하지만 weight의 일시적인 플래핑(flapping)이 있으므로, 이 동작을 이해하고 있어야 해요.
Argo CD를 Argo Rollouts과 함께 사용할 때 이 동작을 막기 위해 따르면 좋은 몇 가지 베스트 프랙티스가 있어요. 다음 Argo CD 기능을 활용하면 돼요.
- VirtualService의 차이를 무시하도록 애플리케이션을 구성해요. 예:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
spec:
ignoreDifferences:
- group: networking.istio.io
kind: VirtualService
jqPathExpressions:
- .spec.http[].route[].weight
VirtualService HTTP route weight의 차이를 무시하면, 그 차이가 Argo CD 애플리케이션의 전체 sync 상태에 기여하지 못하게 돼요. 이는 자동 sync(auto-sync) 작업이 트리거되는 것도 방지하는 추가 이점이 있어요.
- OutOfSync 리소스에만 적용하도록 애플리케이션을 구성해요.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
spec:
syncPolicy:
syncOptions:
- ApplyOutOfSyncOnly=true
- RespectIgnoreDifferences=true
기본적으로 Argo CD는 애플리케이션을 sync할 때 애플리케이션에 속한 git의 모든 리소스에 kubectl apply를 실행해요. ApplyOutOfSyncOnly=true sync 옵션은 Argo CD가 이미 Synced로 간주하는 리소스의 적용을 건너뛰고 OutOfSync인 것만 적용하라고 지시해요. 이 옵션을 ignoreDifferences 기능과 함께 쓰면 Argo CD와 Argo Rollouts 사이의 VirtualService 원하는 상태 충돌을 관리할 수 있어요.
Argo CD의 diffing 동작에 대한 자세한 내용은 Argo CD 2.3 버전에서 도입된 managedFieldsManagers 옵션도 참고하세요.
Ping Pong
중요 (Important)
v1.7부터 사용 가능해요.
Argo Rollouts은 Istio를 사용할 때도 ping pong을 지원해요. 이는 ALB와 Istio 트래픽 라우터를 동시에 구성하는 것을 지원하기 위해 추가됐어요. ALB를 사용할 때 ping-pong은 일반적으로 베스트 프랙티스인데, 특히 ALB readiness gates가 활성화된 경우 그렇죠. 하지만 rollout이 abort될 때 service selector를 안정 pod hash로 되돌리면 라벨 변경 때문에 ALB 컨트롤러가 잠시 pod readiness gates를 false로 설정해서 트래픽 장애(blip)가 생겨요. ALB와 Istio를 ping-pong으로 함께 구성하면 이런 selector 변경이 일어나지 않아서 장애가 없어요.
고려된 대안 (Alternatives Considered)
Virtual Service에 대한 Rollout 소유권 (Rollout ownership over the Virtual Service)
초기 설계 대안은 컨트롤러가 참조된 VirtualService를 수정하는 대신, Rollout 컨트롤러가 Virtual Service를 생성·관리·소유하는 것이었어요. 이 접근 방식은 GitOps에 친숙하지만 다른 문제를 일으켜요.
- Rollout 안에서 VirtualService를 참조할 때와 같은 유연성을 제공하려면 Rollout이 Istio spec의 많은 부분을 인라인해야 해요. 하지만 네트워킹은 Rollout의 책임 밖이며, Rollout spec을 불필요하게 복잡하게 만들어요.
- Istio가 새 기능을 도입하면, 그 기능은 Argo Rollouts에서 구현될 때까지 Argo Rollouts에서 사용할 수 없어요.
이 두 문제는 Virtual Service를 참조하는 것보다 사용자와 Argo Rollouts 개발자 모두에게 더 많은 복잡성을 더해요.
SMI Adapter for Istio를 통한 Istio 지원 (Istio support through the SMI Adapter for Istio)
SMI는 Service Mesh Interface로, 서비스 메시의 모든 공통 기능을 위한 표준 인터페이스 역할을 해요. 이 기능은 GitOps에 친숙하지만, 네이티브 Istio에는 SMI가 현재 제공하지 않는 추가 기능이 있어요.