virtual-kubelet开源项目

我要开发同款
匿名用户2021年11月26日
106阅读
所属分类Google Go、云计算、云原生
授权协议Apache-2.0 License

作品详情

VirtualKubelet

VirtualKubeletisanopensourceKuberneteskubeletimplementationthatmasqueradesasakubeletforthepurposesofconnectingKubernetestootherAPIs.ThisallowsthenodestobebackedbyotherserviceslikeACI,AWSFargate,IoTEdge,TensileKubeetc.TheprimaryscenarioforVKisenablingtheextensionoftheKubernetesAPIintoserverlesscontainerplatformslikeACIandFargate,thoughweareopentoothers.However,itshouldbenotedthatVKisexplicitlynotintendedtobeanalternativetoKubernetesfederation.

VirtualKubeletfeaturesapluggablearchitectureanddirectuseofKubernetesprimitives,makingitmucheasiertobuildon.

WeinvitetheKubernetesecosystemtojoinusinempoweringdeveloperstobuilduponourbase.Joinourslackchannelnamed,virtual-kubelet,withintheKubernetesslackgroup.

Thebestdescriptionis"KubernetesAPIontop,programmableback."

TableofContentsHowItWorksUsageProvidersAdmiraltyMulti-ClusterSchedulerAlibabaCloudECIProviderAzureContainerInstancesProviderAzureBatchGPUProviderAWSFargateProviderElotlKipHashiCorpNomadLiqoOpenStackZunTensileKubeProviderAddingaNewProviderviatheProviderInterfaceTestingUnittestsEnd-to-endtestsKnownquirksandworkaroundsContributingHowItWorks

ThediagrambelowillustrateshowVirtual-Kubeletworks.

Usage

VirtualKubeletisfocusedonprovidingalibrarythatyoucanconsumeinyourprojecttobuildacustomKubernetesnodeagent.

Seegodocforuptodateinstructionsonconsumingthisproject:https://godoc.org/github.com/virtual-kubelet/virtual-kubelet

Thereareimplementationsavailableforseveralproviders,seethosereposfordetailsonhowtodeploy.

CurrentFeaturescreate,deleteandupdatepodscontainerlogs,exec,andmetricsgetpod,podsandpodstatuscapacitynodeaddresses,nodecapacity,nodedaemonendpointsoperatingsystembringyourownvirtualnetworkProviders

Thisprojectfeaturesapluggableproviderinterfacedeveloperscanimplementthatdefinestheactionsofatypicalkubelet.

Thisenableson-demandandnearlyinstantaneouscontainercompute,orchestratedbyKubernetes,withouthavingVMinfrastructuretomanageandwhilestillleveragingtheportableKubernetesAPI.

Eachprovidermayhaveitsownconfigurationfile,andrequiredenvironmentalvariables.

ProvidersmustprovidethefollowingfunctionalitytobeconsideredasupportedintegrationwithVirtualKubelet.

Providestheback-endplumbingnecessarytosupportthelifecyclemanagementofpods,containersandsupportingresourcesinthecontextofKubernetes.ConformstothecurrentAPIprovidedbyVirtualKubelet.DoesnothaveaccesstotheKubernetesAPIServerandhasawell-definedcallbackmechanismforgettingdatalikesecretsorconfigmaps.AdmiraltyMulti-ClusterScheduler

AdmiraltyMulti-ClusterSchedulermutatesannotatedpodsinto"proxypods"scheduledonavirtual-kubeletnodeandcreatescorresponding"delegatepods"inremoteclusters(actuallyrunningthecontainers).Afeedbackloopupdatesthestatusesandannotationsoftheproxypodstoreflectthestatusesandannotationsofthedelegatepods.YoucanfindmoredetailsintheAdmiraltyMulti-ClusterSchedulerdocumentation.

AlibabaCloudECIProvider

AlibabaCloudECI(ElasticContainerInstance)isaservicethatallowyouruncontainerswithouthavingtomanageserversorclusters.

YoucanfindmoredetailsintheAlibabaCloudECIproviderdocumentation.

ConfigurationFile

ThealibabaECIproviderwillreadconfigurationfilespecifiedbythe--provider-configflag.

TheexampleconfigurefileisintheECIproviderrepository.

AzureContainerInstancesProvider

TheAzureContainerInstancesProviderallowsyoutoutilizebothtypicalpodsonVMsandAzureContainerinstancessimultaneouslyinthesameKubernetescluster.

YoucanfinddetailedinstructionsonhowtosetitupandhowtotestitintheAzureContainerInstancesProviderdocumentation.

ConfigurationFile

TheAzureconnectorcanuseaconfigurationfilespecifiedbythe--provider-configflag.TheconfigfileisinTOMLformat,andanexamplelivesinproviders/azure/example.toml.

AWSFargateProvider

AWSFargateisatechnologythatallowsyoutoruncontainerswithouthavingtomanageserversorclusters.

TheAWSFargateproviderallowsyoutodeploypodstoAWSFargate.YourpodsonAWSFargatehaveaccesstoVPCnetworkingwithdedicatedENIsinyoursubnets,publicIPaddressestoconnecttotheinternet,privateIPaddressestoconnecttoyourKubernetescluster,securitygroups,IAMroles,CloudWatchLogsandmanyotherAWSservices.PodsonFargatecanco-existwithpodsonregularworkernodesinthesameKubernetescluster.

EasyinstructionsandasampleconfigurationfileisavailableintheAWSFargateproviderdocumentation.Pleasenotethatthisproviderisnotcurrentlysupported.

ElotlKip

Kipisaproviderthatrunspodsincloudinstances,allowingaKubernetesclustertotransparentlyscaleworkloadsintoacloud.Whenapodisscheduledontothevirtualnode,Kipstartsaright-sizedcloudinstanceforthepod'sworkloadanddispatchesthepodontotheinstance.Whenthepodisfinishedrunning,thecloudinstanceisterminated.

WhenworkloadsrunonKip,yourclustersizenaturallyscaleswiththeclusterworkload,podsarestronglyisolatedfromeachotherandtheuserisfreedfrommanagingworkernodesandstrategicallypackingpodsontonodes.

HashiCorpNomadProvider

HashiCorpNomadproviderforVirtualKubeletconnectsyourKubernetesclusterwithNomadclusterbyexposingtheNomadclusterasanodeinKubernetes.Byusingtheprovider,podsthatarescheduledonthevirtualNomadnoderegisteredonKuberneteswillrunasjobsonNomadclientsastheywouldonaKubernetesnode.

Fordetailedinstructions,followtheguidehere.

LiqoProvider

LiqoimplementsaproviderforVirtualKubeletdesignedtotransparentlyoffloadpodsandservicesto"peered"Kubernetesremotecluster.Liqoiscapableofdiscoveringneighborclusters(usingDNS,mDNS)and"peer"withthem,orinotherwords,establisharelationshiptosharepartoftheclusterresources.Whenaclusterhasestablishedapeering,anewinstanceoftheLiqoVirtualKubeletisspawnedtoseamlesslyextendthecapacityofthecluster,byprovidinganabstractionoftheresourcesoftheremotecluster.TheprovidercombinedwiththeLiqonetworkfabricextendstheclusternetworkingbyenablingPod-to-Podtrafficandmulti-clustereast-westservices,supportingendpointsonbothclusters.

Fordetailedinstruction,followtheguidehere

OpenStackZunProvider

OpenStackZunproviderforVirtualKubeletconnectsyourKubernetesclusterwithOpenStackinordertorunKubernetespodsonOpenStackCloud.YourpodsonOpenStackhaveaccesstoOpenStacktenantnetworksbecausetheyhaveNeutronportsinyoursubnets.EachpodwillhaveprivateIPaddressestoconnecttootherOpenStackresources(i.e.VMs)withinyourtenant,optionallyhavefloatingIPaddressestoconnecttotheinternet,andbind-mountCindervolumesintoapathinsideapod'scontainer.

./bin/virtual-kubelet--provider="openstack"

Fordetailedinstructions,followtheguidehere.

TensileKubeProvider

Tensilekubeiscontributedbytencentgames,whichisproviderforVirtualKubeletconnectsyourKubernetesclusterwithotherKubernetesclusters.ThisproviderenablesusextendingKubernetestoanunlimitedone.Byusingtheprovider,podsthatarescheduledonthevirtualnoderegisteredonKuberneteswillrunasjobsonotherKubernetesclusters'nodes.

AddingaNewProviderviatheProviderInterface

ProvidersconsumethisprojectasalibrarywhichimplementsthecorelogicofaKubernetesnodeagent(Kubelet),andwireuptheirimplementationforperformingtheneccessaryactions.

Thereare3maininterfaces:

PodLifecylceHandler

Whenpodsarecreated,updated,ordeletedfromKubernetes,thesemethodsarecalledtohandlethoseactions.

godoc#PodLifecylceHandler

typePodLifecycleHandlerinterface{//CreatePodtakesaKubernetesPodanddeploysitwithintheprovider.CreatePod(ctxcontext.Context,pod*corev1.Pod)error//UpdatePodtakesaKubernetesPodandupdatesitwithintheprovider.UpdatePod(ctxcontext.Context,pod*corev1.Pod)error//DeletePodtakesaKubernetesPodanddeletesitfromtheprovider.DeletePod(ctxcontext.Context,pod*corev1.Pod)error//GetPodretrievesapodbynamefromtheprovider(canbecached).GetPod(ctxcontext.Context,namespace,namestring)(*corev1.Pod,error)//GetPodStatusretrievesthestatusofapodbynamefromtheprovider.GetPodStatus(ctxcontext.Context,namespace,namestring)(*corev1.PodStatus,error)//GetPodsretrievesalistofallpodsrunningontheprovider(canbecached).GetPods(context.Context)([]*corev1.Pod,error)}

ThereisalsoanoptionalinterfacePodNotifierwhichenablestheprovidertoasynchronouslynotifythevirtual-kubeletaboutpodstatuschanges.Ifthisinterfaceisnotimplemented,virtual-kubeletwillperiodicallycheckthestatusofallpods.

ItishighlyrecommendedtoimplementPodNotifier,especiallyifyouplantorunalargenumberofpods.

godoc#PodNotifier

typePodNotifierinterface{//NotifyPodsinstructsthenotifiertocallthepassedinfunctionwhen//thepodstatuschanges.////NotifyPodsshouldnotblockcallers.NotifyPods(context.Context,func(*corev1.Pod))}

PodLifecycleHandlerisconsumedbythePodControllerwhichisthecorelogicformanagingpodsassignedtothenode.

pc,_:=node.NewPodController(podControllerConfig)//<--instatiatesthepodcontrollerpc.Run(ctx)//<--startswatchingforpodstobescheduledonthenodeNodeProvider

NodeProviderisresponsiblefornotifyingthevirtual-kubeletaboutnodestatusupdates.Virtual-KubeletwillperiodicallycheckthestatusofthenodeandupdateKubernetesaccordingly.

godoc#NodeProvider

typeNodeProviderinterface{//Pingchecksifthenodeisstillactive.//Thisisintendedtobelightweightasitwillbecalledperiodicallyasa//heartbeattokeepthenodemarkedasreadyinKubernetes.Ping(context.Context)error//NotifyNodeStatusisusedtoasynchronouslymonitorthenode.//Thepassedincallbackshouldbecalledanytimethereisachangetothe//node'sstatus.//ThiswillgenerallytriggeracalltotheKubernetesAPIservertoupdate//thestatus.////NotifyNodeStatusshouldnotblockcallers.NotifyNodeStatus(ctxcontext.Context,cbfunc(*corev1.Node))}

VirtualKubeletprovidesaNaiveNodeProviderthatyoucanuseifyoudonotplantohavecustomnodebehavior.

godoc#NaiveNodeProvider

NodeProvidergetsconsumedbytheNodeController,whichiscorelogicformanagingthenodeobjectinKubernetes.

nc,_:=node.NewNodeController(nodeProvider,nodeSpec)//<--instantiateanodecontrollerfromanodeproviderandakubernetesnodespecnc.Run(ctx)//<--createsthenodeinkubernetesandstartsuphecontrollerAPIendpoints

OneoftherolesofaKubeletistoacceptrequestsfromtheAPIserverforthingslikekubectllogsandkubectlexec.Helpersforsettingthisupareprovidedhere

TestingUnittests

Runningtheunittestslocallyisassimpleasmaketest.

End-to-endtests

Checkouttest/e2eformoredetails.

KnownquirksandworkaroundsMissingLoadBalancerIPaddressesforservicesProvidersthatdonotsupportservicediscovery

Kubernetes1.9introducesanewflag,ServiceNodeExclusion,forthecontrolplane'sControllerManager.EnablingthisflagintheControllerManager'smanifestallowsKubernetestoexcludeVirtualKubeletnodesfrombeingaddedtoLoadBalancerpools,allowingyoutocreatepublicfacingserviceswithexternalIPswithoutissue.

Workaround

Clusterrequirements:Kubernetes1.9orabove

EnabletheServiceNodeExclusionflag,bymodifyingtheControllerManagermanifestandadding--feature-gates=ServiceNodeExclusion=truetothecommandlinearguments.

Contributing

VirtualKubeletfollowstheCNCFCodeofConduct.SigntheCNCFCLAtobeabletomakePullRequeststothisrepo.

MonthlyVirtualKubeletOfficeHoursareheldat10amPSTonthelastThursdayofeverymonthinthiszoommeetingroom.Checkoutthecalendarhere.

Ourgoogledrivewithdesignspecificationsandmeetingnotesarehere.

Wealsohaveacommunityslackchannelnamedvirtual-kubeletintheKubernetesslack.YoucanalsoconnectwiththeVirtualKubeletcommunityviathemailinglist.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论