06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google,...

34
Kubernetes Continued Cloud-native PhD Course at LTH Fall 2019 Lars Larsson

Transcript of 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google,...

Page 1: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesContinuedCloud-nativePhDCourseatLTH

Fall2019LarsLarsson

Page 2: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

etcd OpenIDConnect

DesignPatterns

HelmPackageManager

Page 3: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

• Architecture• Networking• Security• NetworkPolicies• Role-BasedAccessControltoKubernetesAPI

• Storage• Extensions

Page 4: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Architecture

Page 5: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Networking

Page 6: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Networking::PodtoPod

• ContainerNetworkInterface(CNI)• Manydifferentproviders• Differentfunctionality(L2orL3inOSIterms)• Flannel,Calico,andWeavemostcommon

• Essentiallytunnelinter-Podtrafficine.g.UDPpacketsbetweennodes• UseprotocollikeARP,BGP,orevenjustdatastoredetcdfordestination

• Readmore• ClusterNetworking

Page 7: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Networking::Services

• ServicesgetvirtualIPsreachableoneachhost• ForwardstraffictoregisteredEndpoints(Podsw/successfulliveness)• Managedbykube-proxy

• Serviceimplementations• (user-space–nolongerused)• Iptables(commondefault)• IPVS(high-performanceandhighscalability)

• Furtherreading• Services

Page 8: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::NetworkPolicies

Page 9: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::NetworkPolicies

• Limitincomingandoutgoingtrafficto/fromPods• Think"firewall"

• RequiressupportfromCNIprovider!

• ExampleYAMLdefinitiononnextslide

• Furtherreading• NetworkPolicies

Page 10: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::NetworkPolicy::ExampleapiVersion:networking.k8s.io/v1kind:NetworkPolicymetadata:name:test-network-policynamespace:defaultspec:podSelector:matchLabels:role:dbpolicyTypes:-Ingress-Egressingress:-from:-ipBlock:cidr:172.17.0.0/16except:-172.17.1.0/24-namespaceSelector:matchLabels:project:myproject-podSelector:matchLabels:role:frontendports:-protocol:TCPport:6379egress:-to:-ipBlock:cidr:10.0.0.0/24ports:-protocol:TCPport:5978

Podsthispolicypertainsto

AllowincomingfromIPrange...

...orfromanyinthisnamespace...

...orany"frontend"labeledPod...

...forTCPtrafficonthisport.

AllowoutgoingonlytothisIPrangeandonlyTCPtrafficonthisport

Page 11: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::Role-BasedAccessControl

Page 12: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::Role-BasedAccessControl

• AllAPIcallshappenwithincontextofsomeuser• Canassignrolestousersviaabinding

• Role(namespaced)vs.ClusterRole(notconfinedtonamespace)• RoleBindingvs.ClusterRoleBinding

• APIGroups,Resources,Verbs• Subjects{User,Group,ServiceAccount}

• Furtherreading• UsingRBACAuthorization• Authenticating

Page 13: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Security::Role-BasedAccessControl::ExampleapiVersion:rbac.authorization.k8s.io/v1kind:Rolemetadata:namespace:defaultname:pod-readerrules:-apiGroups:[""]#""indicatesthecoreAPIgroupresources:["pods"]verbs:["get","watch","list"]

apiVersion:rbac.authorization.k8s.io/v1kind:RoleBindingmetadata:name:read-podsnamespace:defaultsubjects:-kind:Username:jane#NameiscasesensitiveapiGroup:rbac.authorization.k8s.ioroleRef:kind:Role#thismustbeRoleorClusterRolename:pod-reader#mustmatchnameofRoleapiGroup:rbac.authorization.k8s.io

Page 14: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Storage

Page 15: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Storage

• PersistentVolumesupportviaContainerStorageInterface(CSI)• Cloud-specificones(e.g.Cinder)• NetworkedFileSystems(e.g.NFS,GlusterFS,…)• Proprietaryones(e.g.Portworx)

• StorageClasschosenforPersistentVolume

• Furtherreading• PersistentVolumes• StorageClasses• DynamicVolumeProvisioning

Page 16: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Extensions

Page 17: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Extensions

• CustomResourceDefinition(CRD)• AddcustomAPIobject• Immediatefirst-classsupportine.g.kubectl

• TypicallyCRDtiedtosomeController/Operator• ActsupondatamanagedinCRDobject

• Furtherreading• CustomResources• ExtendtheKubernetesAPIwithCustomResourceDefinitions

Page 18: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

etcd OpenIDConnect

DesignPatterns

HelmPackageManager

Page 19: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

etcd

• Distributedkey-valuestore

• ThecorecomponentinKubernetes• Singlesourceoftruth• StoresstateofallAPIobjectsandalleventsthatoccur• APIservicefrontendtoetcd

• Raftprotocol• Sensitivetoslownetworksandslowdiskperformance

• Furtherreading• Learningetcd• RaftConsensusAlgorithm(hascoolanimation!)

Page 20: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

etcd OpenIDConnect

DesignPatterns

HelmPackageManager

Page 21: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

OpenIDConnect

• Enablesthird-partyauthentication• Google,Facebook,Twitter,…

• KubernetescanuseOpenIDConnecttogetherwithRBAC• Dexeasytosetup

• ResourceServer:serviceyouwanttouse• Client:softwareyouusetoauthenticate(webbrowser!)• AuthenticationServer/IdentityProvider(IdP):servicethatauthenticatesyou

Page 23: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

etcd OpenIDConnect

DesignPatterns

HelmPackageManager

Page 24: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPatternsinKubernetes

Sidecar Ambassador Adapter

Leaderelection Workqueue Scatter/gather

Page 25: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Sidecar

• Oneprocesspercontainer• Sodoyoubakeinallfunctionalityintoone?

• Sidecarisahelpertomainprocess• E.g.Synchronizingfilecontents,samplingrequests,managinglogfiles...

• Composability!

Page 26: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Ambassador

• Proxiesand(typically)simplifiescallsfrommainprocesstoaservice

• Hidescomplexity

• Reducescoupling

Page 27: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Adapter

• Proxiesand(typically)simplifiescallstomainprocessfromaservice

• Hidescomplexity

• Reducescoupling

• E.g.ametricscollectionservicecanassumethatallourPodsarecompatiblewithsomeprotocolX–eithernativelyorviaanadapter

Page 28: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Leaderelection

• Distributedalgorithms(upcominglecture!)oftenneedaleaderorcoodinator• Thisisverycomplex(andtheoreticallyimpossible)!• Whyre-inventthewheel?Justoffera"leaderelection"containerandinterfacewithit!

p0

p1

p2p3

p4

Page 29: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Workqueue

• Dataprocessingcanoftenbedoneinparallel

• Moreworkers=lesswaitingonresults

• Createaworkqueueandspawnasmanyworkersasyoucan(afford)• Eachworkerisassignedtasksandmarksascompleted• Workerfailure?Workitemnotmarkedasfinished,sootherworkerclaimsit

Page 30: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

DesignPattern::Scatter/gather

• Dataprocessingcanoftenbedoneinparallel

• Moreworkers=lesswaitingonresults

• Haveworkersworkonsub-problems!• Coordinatingprocesscollectssub-resultsandcreatesoverallresult

Page 31: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

KubernetesUndertheHood

etcd OpenIDConnect

DesignPatterns

HelmPackageManager

Page 32: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

HelmPackageManager

• Fullyfeaturedapplicationscangetquitecomplex!

• Helmletsyoudeployapplicationsas-a-whole("Charts")• Templatelanguagefordifferencesindeploymentsandvariables• Manageslife-cycleofentireapplication,notitsparts

• Tiller:(optionalbutuseful)server-sidecomponent• Helm:command-lineinterfacetool

• Furtherreading• Helmdocumentation

Page 33: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Summary

• Kubernetesarchitectureishighlymodular• Plug-and-play,usewhatyouwant,makeityours• ExtensibleAPIaswell

• etcdisthesinglesourceofalltruthinKubernetes

• OpenIDConnectletsapplicationsauthenticateusersviathirdparty

• Designpatternshelpyouquicklystandupaservicewithstandardcomponentsandabstractions

• Helmpackagemanagercanhelpdeployevencomplexapplicationsandmanagetheirlife-cycle

Page 34: 06 - Kubernetes continued€¦ · OpenID Connect • Enables third-party authentication • Google, Facebook, Twitter, … • Kubernetes can use OpenID Connect together with RBAC

Nextweek-Distributedsystems