Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tour of Istio

Yuki Ito
March 10, 2021

Tour of Istio

Yuki Ito

March 10, 2021
Tweet

More Decks by Yuki Ito

Other Decks in Technology

Transcript

  1. Current Solutions e.g. k8sdns Resolver Pod 10.28.1.11 Pod 10.28.1.12 Pod

    10.28.1.13 Headless Service hs-serivce.foo.svc.cluster.local gRPC Client 10.28.1.11 10.28.1.12 10.28.1.13 k8sdns:///hs-service.foo
  2. Current Solutions e.g. Pod ratio based canary release Pod Pod

    Pod Service selector: app=foo Main Deployment app=foo Canary Deployment app=foo
  3. Service Mesh The term service mesh is used to describe

    the network of microservices that make up such applications and the interactions between them. https://istio.io/latest/docs/concepts/what-is-istio/
  4. Without Istio -- - kind: Namespac e metadata : name:

    a -- - kind: Deploymen t metadata : name: a namespace: a spec : template : spec : containers : - name: a image: nginx
  5. With Istio -- - kind: Namespac e metadata : name:

    a labels: istio-injection: enabled -- - kind: Deploymen t metadata : name: a namespace: a spec : template : metadata : annotations : sidecar.istio.io/inject: tru e spec : containers : - name: a image: nginx
  6. Sidecar Pattern Sidecar Application Pod Extract non application related logics

    to the Sidecar container from the Application container. - Networking - Authentication / Authorization - Tracing etc...
  7. Sidecar Injection -- - kind: Namespac e metadata : name:

    a labels: istio-injection: enabled -- - kind: Deploymen t metadata : name: a namespace: a spec : template : metadata : annotations : sidecar.istio.io/inject: tru e spec : containers : - name: ap p image: nginx
  8. Sidecar Injection kind: Po d spec : containers : -

    name: ap p image: ngin x - name: istio-prox y image: docker.io/istio/proxyv2:1.8.1
  9. Sidecar Injection kubectl kube-apiserver etcd Mutating Admission Webhook YAML Modi

    fi ed YAML YAML Modi fi ed YAML https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/
  10. Init Container Specialized containers that run before app containers in

    a Pod. Init containers can contain utilities or setup scripts not present in an app image. https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
  11. Init Container kind: Po d spec : containers : -

    name: ap p image: ngin x - name: istio-prox y image: docker.io/istio/proxyv2:1.8.1
  12. Init Container kind: Po d spec : containers : -

    name: ap p image: ngin x - name: istio-prox y image: docker.io/istio/proxyv2:1.8. 1 initContainers : - name: istio-ini t image: docker.io/istio/proxyv2:1.8. 1 args : - istio-iptables (via Mutating Admission Webhook)
  13. Linux Namespaces for Pod Network / IPC / PID /

    Mount / UTS Container 1 Container 2 cgroup cgroup
  14. Init Container > pilot-agent \ istio-iptables \ -p 15001 \

    -z 15006 \ -u 1337 \ -m REDIRECT \ -i * \ -x \ -b * \ -d
  15. iptables > ssh <Kubernetes Node > > sudo nsenter --net

    --target <app container PID > > iptables --table nat --lis t #.. . Chain ISTIO_IN_REDIRECT (3 references ) target prot opt source destinatio n REDIRECT tcp -- anywhere anywhere redir ports 1500 6 Chain ISTIO_REDIRECT (1 references ) target prot opt source destinatio n REDIRECT tcp -- anywhere anywhere redir ports 15001
  16. Inbound Tra ffi c PREROUTING POSTROUTING Application Linux Kernel Space

    (iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ
  17. Inbound Tra ffi c PREROUTING ISTIO_INBOUND ISTIO_IN_REDIRECT ISTIO_OUTPUT POSTROUTING OUTPUT

    istio-proxy PORT: 15006 Application Linux Kernel Space (iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ ᶆ ᶇ ᶈ ᶉ ᶊ
  18. Outbound Tra ffi c OUTPUT POSTROUTING Application Linux Kernel Space

    (iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ
  19. Outbound Tra ffi c OUTPUT ISTIO_REDIRECT POSTROUTING ISTIO_OUTPUT istio-proxy PORT:

    15001 Application Linux Kernel Space (iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ ᶆ ᶈ ᶇ ᶉ ᶊ ᶋ
  20. Istio iptables Implementation func (r *RealDependencies) execute(cmd string, redirectStdout bool,

    args ...string) error { fmt.Printf("%s %s\n", cmd, strings.Join(args, " ") ) externalCommand := exec.Command(cmd, args...) externalCommand.Stdout = os.Stdou t // TODO Check naming and redirection logic if !redirectStdout { externalCommand.Stderr = os.Stder r } return externalCommand.Run( ) } https://github.com/istio/istio/blob/95c5fe4026f5a395893e92e1c9297a03b06b7dd4/tools/istio-iptables/pkg/dependencies/implementation.go#L27-L36
  21. Envoy Envoy is an L7 proxy and communication bus designed

    for large modern service oriented architectures. The project was born out of the belief that:ɹ The network should be transparent to applications. When network and application problems do occur it should be easy to determine the source of the problem. https://www.envoyproxy.io/docs/envoy/v1.16.2/intro/what_is_envoy
  22. Envoy Con fi gurations 0.0.0.0:5000 Listener Route Service-1 Cluster 10.28.1.11

    10.28.1.12 10.28.1.13 10.28.1.14 Service-2 Cluster Path: /service-1 Path: /service-2
  23. x Discovery Service API •Listener Discovery Service •Route Discovery Service

    •Cluster Discovery Service •Endpoint Discovery Service
  24. go-control-plane import ( cache ".../go-control-plane/pkg/cache/v3" server ".../go-control-plane/pkg/server/v3 " discovery ".../go-control-plane/envoy/service/discovery/v3"

    "google.golang.org/grpc" ) // ... snapshotCache := cache.NewSnapshotCache(... ) server := server.NewServer(ctx, snapshotCache, ... ) grpcServer := grpc.NewServer( ) lis, _ := net.Listen("tcp", ":8081" ) discovery.RegisterAggregatedDiscoveryServiceServer(grpcServer, server ) grpcServer.Serve(lis) Minimum Implementation
  25. istiod uses spf13/cobra import ( //.. "github.com/spf13/cobra" ) var (

    //.. . rootCmd = &cobra.Command { Use: "pilot-discovery" , Short: "Istio Pilot." , Long: "..." , SilenceUsage: true , } https://github.com/istio/istio/blob/95c5fe4026f5a395893e92e1c9297a03b06b7dd4/pilot/cmd/pilot-discovery/main.go#L43-L48
  26. e.g. VirtualService apiVersion: networking.istio.io/v1alpha 3 kind: VirtualServic e metadata :

    name: microservice- a namespace: microservice- a spec : hosts : - microservice-a.microservice-a.svc.cluster.loca l http : - match : - headers : target : exact: fo o route : - destination : host: microservice-a-foo.microservice-a.svc.cluster.loca l # ... VirtualService