Share
Embed
Transcript
61 slides
-
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 -
Current Solutions e.g. Pod ratio based canary release Pod Pod
Pod Service selector: app=foo Main Deployment app=foo Canary Deployment app=foo -
Problems ɾMust modify the application itself ɾPolyglot ɾNot a fi
ne grained canary releasing -
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/ -
Without Istio -- - kind: Namespac e metadata : name:
a -- - kind: Deploymen t metadata : name: a namespace: a spec : template : spec : containers : - name: a image: nginx -
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 -
Sidecar Pattern Sidecar Application Pod Extract non application related logics
to the Sidecar container from the Application container. - Networking - Authentication / Authorization - Tracing etc... -
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 -
Sidecar Injection kind: Po d spec : containers : -
name: ap p image: nginx -
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 -
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/ -
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/ -
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 -
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) -
Linux Namespaces for Pod Network / IPC / PID /
Mount / UTS Container 1 Container 2 cgroup cgroup -
Init Container > pilot-agent \ istio-iptables \ -p 15001 \
-z 15006 \ -u 1337 \ -m REDIRECT \ -i * \ -x \ -b * \ -d -
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 -
Inbound Tra ffi c PREROUTING POSTROUTING Application Linux Kernel Space
(iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ -
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 ᶃ ᶄ ᶅ ᶆ ᶇ ᶈ ᶉ ᶊ -
Outbound Tra ffi c OUTPUT POSTROUTING Application Linux Kernel Space
(iptables / net fi lter) Linux User Space ᶃ ᶄ ᶅ -
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 ᶃ ᶄ ᶅ ᶆ ᶈ ᶇ ᶉ ᶊ ᶋ -
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 -
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 -
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 -
x Discovery Service API •Listener Discovery Service •Route Discovery Service
•Cluster Discovery Service •Endpoint Discovery Service -
Control Plane Control Plane Con fi g Con fi g
Con fi g xDS API -
Control Plane istiod Con fi g Con fi g Con
fi g xDS API -
Control Plane istiod Con fi g Con fi g Con
fi g xDS API -
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 -
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 -
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 -
e.g. VirtualService Route microservice-a 10.28.1.11 10.28.1.12 10.28.1.13 10.28.1.14 microservice-a-foo default
target: foo microservice-a.microservice-a.svc.cluster.local