Share
Embed
Istioと共にマイクロサービスに立ち向かえ!
Japan Container Days V18.04
PDF: https://drive.google.com/file/d/1BfHG7WEbKY1P1FOG9tpTKxVZ-JeReEU5/view?usp=sharing
Aya (Igarashi) Ozawa
April 20, 2018
Transcript
47 slides
-
Istio x KubernetesͰ ͦΕΒͷΛͲ͏ղܾ ͢Δͷ͔? ͍ͨ͜͠ͱ Istioʹೖ͢Δʹ? ෳࡶʹͳͬͨ Microservicesύλʔϯ ͷγεςϜ͕࣋ͭ
1 2 3 ͭΒ͍…. Αͦ͞͏ ͬͯΈΑ͏ -
ෳࡶͳγεςϜ͕ͨΒ͢ 1 2 3 4 γεςϜͷશମ૾͕ѲͰ͖ͳ͍ ΞϓϦέʔγϣϯؒͷ௨৴Λ੍ޚ͖͠Εͳ͍ 伴ͱূ໌ॻΛཧ͖͠Εͳ͍ ো࣌ʹԿ͕ى͜Δ͔͔Βͳ͍ Traffic
Management Security Visualization Chaos Engineering -
ͲͷΑ͏ʹServiceMeshΛཧ͍ͯ͠Δͷ͔? Pod App Envoy App Pod Pilot Mixer Auth Istio
Controle Plane Data Plane Config data ֤ΞϓϦέʔγϣϯͷखલʹϓ ϩΩγαʔόΛஔ͖ɺ͜ͷϓϩ ΩγͷઃఆΛControle Plane͔ ΒAPIܦ༝Ͱ੍ޚ͢Δ Envoy -
Envoyͱ? App Envoy C++11Ͱॻ͔Εͨ L4/L7 proxy LyftʹΑͬͯ։ൃ͞ΕͨOSS APIܦ༝ͷઃఆมߋ͕Մೳ ઃఆมߋ࣌ʹrestart͕ෆཁ HTTP/2
& GRPC ʹରԠ Proxy in/out-bound Traffic -
ղܾࡦ1 ServiceMeshͷઃఆΛ apiVersion: networking.istio.io/v1alpha3 kind: VirtualService …. spec: # ϦΫΤετͷѼઌΛࢦఆ
hosts: - myapp http: - match: - uri: # URI ʹ /v1/oldHome Λ͍࣋ͬͯΔ # ϦΫΤετʹϚον exact: /v1/oldHome redirect: # /v1/newHome ʹϦμΠϨΫτ uri: /v1/newHome authority: myapp.default.svc.cluster.local ServiceMeshͷઃఆ͕ΞϓϦέʔγϣ ϯίʔυʹґଘ͠ͳ͍ L7LBʹΑͬͯॊೈͳϧʔςΟϯά͕ Ͱ͖Δ ։ൃऀͱӡ༻ऀ͕ۀ͍͢͠ • ΧφϦΞʔϦϦʔεͰ҆৺ͳupgrade • ϦΫΤετΛϓϩμΫγϣϯͱ εςʔδϯάڥͷϛϥʔ • pathʹΑͬͯΞϓϦέʔγϣϯΛ͚Δ • ܞଳͱPCͳͲΫϥΠΞϯτʹԠͨ͡ৼΓ͚ -
TrafficΛEnvoyʹྲྀ͢Έ Init Istio App K8s 1. Deploy App initContainers: -
name: istio-init image: docker.io/istio/proxy_init …. containers: - name: istio-proxy image: docker.io/istio/proxy_debug securityContext: runAsUser: 1337 args: - -p - “15001” …. - name: App image: docker.io/ladicle/myapp ...... 3.Change iptables rules Redirect In&Out bound Traffic UID: 1337 2. Create istio-init 4. Create App and istio-proxy proxy Istio -
istio-initʹΑΔiptablesͷมߋ istio-proxy@productpage-v1-5f9b797dfc-n6rn4:/$ sudo iptables -t nat -n -L -v Chain
PREROUTING (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ISTIO_REDIRECT all -- * * 0.0.0.0/0 0.0.0.0/0 /* istio/install-istio-prerouting */ …. Chain OUTPUT (policy ACCEPT 1024 packets, 96005 bytes) pkts bytes target prot opt in out source destination 21 1260 ISTIO_OUTPUT tcp -- * * 0.0.0.0/0 0.0.0.0/0 /* istio/install-istio-output */ …. Chain ISTIO_OUTPUT (1 references) pkts bytes target prot opt in out source destination 0 0 ISTIO_REDIRECT all -- * lo 0.0.0.0/0 !127.0.0.1 /* istio/redirect-implicit-loopback */ 19 1140 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0 owner UID match 1337 /* istio/bypass-envoy */ 0 0 RETURN all -- * * 0.0.0.0/0 127.0.0.1 /* istio/bypass-explicit-loopback */ 2 120 ISTIO_REDIRECT all -- * * 0.0.0.0/0 0.0.0.0/0 /* istio/redirect-default-outbound */ Chain ISTIO_REDIRECT (3 references) pkts bytes target prot opt in out source destination 2 120 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 /* istio/redirect-to-envoy-port */ redir ports 15001 Redirect all Traffic to Envoy Except own & lo -
K8s ServiceMeshͷઃఆΛม͑Δ App 1. Call Rules API proxy Istio 3.
Call Envoy API Pilot 2. Detect changes of service-account 4. Update Envoy Config listeners: - address: socket_address: address: 0.0.0.0 port_value: 15004 filter_chains: - filters: …. http_filters: - config: default_destination_service: istio-pol service_configs: istio-policy.{{ .PodNamespace }}.svc disable_check_calls: true mixer_attributes: attributes: -
2 伴ͱূ໌ॻΛཧ͖͠Εͳ͍ γεςϜʹΑͬͯΞϓϦέʔγϣϯؒ௨ ৴ͷ҉߸Խඞਢ ΞϓϦέʔγϣϯ͕ଟ͘ͳΔͱɺ Difficult Key & Certificate Management
ҰͭҰͭ伴ূ໌ॻͷੜɺɺߋ৽ɺ ແޮԽʹରԠ͢Δ͕࣌ؒͳ͘ͳΔ -
ղܾࡦ2 伴ͱূ໌ॻͷཧΛࣗಈԽ 伴ͱূ໌ॻͷੜ, , ߋ৽, ഇࢭʹରԠ͍ͯ͠Δ K8s 1. Deploy App
3. Generate self signed key & cert 7. Push Secure Naming 5. Deploy Pod with Secret 2. Detect service account change CA Istio 4. Store to Secret Pilot 6. Watch Secure Naming Foo proxy Istio (SD) Mutual TLS(૬ޓTLS)Λαϙʔτ SAN: “spiffe://…/foo” mTLS Bar proxy Istio SAN: “spiffe://…/bar” ref: https://spiffe.io/ -
IstioͱPrometheus͕Ͳ͏࿈ܞ͢Δͷ͔? # Rule to send metric instances to a Prometheus
handler apiVersion: "config.istio.io/v1alpha2" kind: rule metadata: name: mongoprom namespace: default spec: match: context.protocol == "tcp" && destination.service == "mongodb.default.svc.cluster.local" actions: - handler: mongohandler.prometheus instances: - mongoreceivedbytes.metric - mongosentbytes.metric # Configuration for a Prometheus han apiVersion: "config.istio.io/v1alpha2" kind: prometheus metadata: name: mongohandler namespace: default spec: metrics: - name: mongo_sent_bytes # Prometh instance_name: mongosentbytes.me kind: COUNTER label_names: - source_service - source_version - destination_version - name: mongo_received_bytes # Prom instance_name: mongoreceivedbytes ௨৴ܥͷMetricsউखʹ औͬͯ͘ΕΔ σϑΥϧτͷMetrics͔Β ServiceGraphΛੜͰ͖Δ -
IstioͱTraces͕Ͳ͏࿈ܞ͢Δͷ͔? ࣗಈతʹεύϯΛૹ৴Ͱ͖Δ τϨʔεશମΛؔ࿈͚ͮΔ͜ͱͰ͖ͳ͍ ҎԼͷϔομΛࢠʹൖͤ͞Δ͜ͱͰؔ࿈͚ͮͰ͖Δ • x-request-id • x-b3-traceid • x-b3-spanid
• x-b3-parentspanid • x-b3-sampled • x-b3-flags • x-ot-span-context def getForwardHeaders(request): headers = {} user_cookie = request.cookies.get("user") if user_cookie: headers['Cookie'] = 'user=' + user_cookie incoming_headers = [ 'x-request-id', 'x-b3-traceid', 'x-b3-spanid', 'x-b3-parentspanid', 'x-b3-sampled', 'x-b3-flags', 'x-ot-span-context' ] for ihdr in incoming_headers: val = request.headers.get(ihdr) if val is not None: headers[ihdr] = val -
Mixer͕Backendͱ࿈ܞ͢ΔΈ App proxy Istio K8s Update Mixer Config Mixer Adapters
Report attributes Backends ΞϓϦέʔγϣϯίʔυͱBackendΛհ MixterΛڬΉ͜ͱͰӡ༻ऀ੍͕ޚͰ͖Δ AdapterΛՃͯ͠ಠࣗͷBackendΛ૿ͤΔ -
ղܾࡦ4 Fault InjectionͰোʹඋ͑Δ ରൣғͱো༰Λࢦఆ͢Δ͚ͩͰ खܰʹোΛ࣮ݧͰ͖Δ apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata:
name: reviews-route spec: …. fault: delay: percent: 10 fixedDelay: 5s …. fault: abort: percent: 10 httpStatus: 400 ࢦఆ͞Εׂͨ߹ͷϦΫΤετʹରͯ͠ Delay: ࢦఆ͞Ε͚ͨ࣌ؒͩΒͤΔ Abort: ֘ͷεςʔλείʔυΛฦ͢ Chaos http2Error grpcStatus࣮༧ఆ -
ղܾࡦ4 Circuit BrakerͰোΛ࠷খݶʹ͑Δ apiVersion: config.istio.io/v1alpha2 kind: RouteRule metadata: name: ratings-delay
spec: … httpFault: delay: percent: 10 fixedDelay: 5s apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule … trafficPolicy: connectionPool: tcp: maxConnections: 100 http: http2MaxRequests: 1000 maxRequestPerConnection: 10 outlinerDetection: http: consecutiveErrors: 7 Interval: 5m baseEjectionTime: 10 ίʔυΛॻ͔ͣʹΤϥʔ͕ଓ͘ΞϓϦ έʔγϣϯͷϦΫΤετΛःஅ͢Δ Add x-envoy-overloaded Block Block Break -
͓͞Β͍ 1 2 3 4 γεςϜͷશମ૾͕ѲͰ͖ͳ͍ ServiceMeshΛ੍ޚ͖͠Εͳ͍ 伴ͱূ໌ॻΛཧ͖͠Εͳ͍ ো࣌ʹԿ͕ى͜Δ͔Θ͔Βͳ͍ ՄࢹԽπʔϧͱ࿈ܞ
& ࣗಈԽΛαϙʔτ ServiceMeshͷઃఆΛ͢Δ ηΩϡΞ௨৴ͷͨΊͷ伴Λཧ͖͠Εͳ͍ FIT & CircuitBrakerͰোʹඋ͑Δ -
ଞʹ ৭ʑͰ͖·͢! Policy Enforcement Role Base Access Control Rate Limit
Control Ingress Traffic Control Egress Traffic Integrate Bare Metal Logging Request Timeout Deploy to Eureka ɹɹɹɹɹMesos, CF -
ೖνϟʔτ C B D Start ͜ͷϓϨθϯ Λฉ͍ͯ֓ཁ ΛѲͨ͠ IstioڥΛ ηοτΞοϓ
ͨ͠ ڭ͑ͯཉ͍͠ ͜ͷൃදͰ ؾʹͳΔ Topic͕͋Δ A YES YES YES Istio ॳ৺ऀͩ IstioΛશʹ ཧղ͍ͯ͠Δ NO YES NO NO ৸ͯͨͱ͜Ζ SpeakerDeckΛcheck! https://speakerdeck.com/ladicle YES E QuickStartΛࢀߟʹ IstioΛΠϯετʔϧ https://istio.io/docs/setup/ kubernetes/quick-start.html GKEͷQuick Start͕Φεεϝ ֘͢ΔTasksΛࢼ͢ https://istio.io/docs/tasks/ NO ཏతͳGuidsͷ νϡʔτϦΞϧΛࢼ͢ https://istio.io/docs/guides/ -
ࠔͬͨ࣌ʁ 1 2 3 4 ͓ࢼ͠தʹτϥϒͬͨ ࣭͕͋Δ 2Ͱղܾ͠ͳ͍࣭͕͋Δ τϥγϡʔΨΠυΛࢀর https://istio.io/help/troubleshooting.html
όάΛݟ͚ͭͨ ॆ࣮ͷFAQΛࢀর https://istio.io/help/faq ҆ఆͷStack Overflow https://stackoverflow.com/questions/tagged/istio GitHubͷIssue https://github.com/istio/issues/issues/