kubeedge: keadm 源码学习

Posted Kris_u

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubeedge: keadm 源码学习相关的知识,希望对你有一定的参考价值。

一、keadm beta init provides a solution for integrating Cloudcore Helm Chart.

func NewInitBeta() *cobra.Command 
1、checkFlags 2、AddInitBeta2ToolsList 3、ExecuteInitBeta    
func NewInitBeta() *cobra.Command 
	BetaInit := newInitBetaOptions()

	tools := make(map[string]types.ToolsInstaller)
	flagVals := make(map[string]types.FlagData)

	var cmd = &cobra.Command
		Use:     "init",
		Short:   "Bootstraps cloud component. Checks and install (if required) the pre-requisites.",
		Long:    cloudBetaInitLongDescription,
		Example: cloudBetaInitExample,
		RunE: func(cmd *cobra.Command, args []string) error 
			checkFlags := func(f *pflag.Flag) 
				util.AddToolVals(f, flagVals)
			
			cmd.Flags().VisitAll(checkFlags)
			err := AddInitBeta2ToolsList(tools, BetaInit)
			if err != nil 
				return err
			
			return ExecuteInitBeta(tools)
		,
	
...
	return cmd

func AddInitBeta2ToolsList(toolList map[string]types.ToolsInstaller, initBetaOpts *types.InitBetaOptions) error 

1、 checkFlags:检查命令行传入的参数

2、GetLatestVersion return the latest non-prerelease, non-draft version of kubeedge in release

若没有获取到最新版本,默认使用1.10.0版本。其次根据initBetaOpts配置一些参数设置

toolList["helm"] = &helm.KubeCloudHelmInstTool

3、ExecuteInitBeta:使用helm安装cloudcore

func (cu *KubeCloudHelmInstTool) InstallTools() error 

两种安装方式:RunHelmInstall、RunHelmManifest

// InstallTools downloads KubeEdge for the specified version
// and makes the required configuration changes and initiates cloudcore.
func (cu *KubeCloudHelmInstTool) InstallTools() error 
	cu.SetOSInterface(util.GetOSInterface())
	cu.SetKubeEdgeVersion(cu.ToolVersion)

	...

	switch cu.Action 
	case types.HelmInstallAction:
		if err := cu.RunHelmInstall(baseHelmRoot); err != nil 
			return err
		
	case types.HelmManifestAction:
		if err := cu.RunHelmManifest(baseHelmRoot); err != nil 
			return err
		
	default:
		fmt.Println("Not support this action")
	

	return nil
1、RunHelmInstall renders the Charts with the given values, then installs the Charts to the cluster.
--force强制安装无论cloudcore是否存在。
// --force would not care about whether the cloud components exist or not
--external helm root 也会强制安装
// Also, if gives a external helm root, no need to check and verify. Because it is always not a cloudcore.
func (cu *KubeCloudHelmInstTool) RunHelmInstall(baseHelmRoot string) error 
	//检查cloudcore是否已经运行以及k8s组件是否安装。
	...
	// prepare to render
	if err := cu.beforeRenderer(baseHelmRoot); err != nil 
		return err
	

	// build a renderer instance with the given values and flagvals
	renderer, err := cu.buildRenderer(baseHelmRoot)
	if err != nil 
		return fmt.Errorf("cannot build renderer: %s", err.Error())
	

	release, err := cu.runHelmInstall(renderer)
	if err != nil 
		return err
	
    ......

	return nil

keadm beta init 安装cloudcore过程中遇到的一个问题:

keadm beta init --advertise-address=124.70.221.xxx --force --profile version=v1.10.0

kubectl get pod -n kubeedge:   cloudcore的状态是Pending

[root@huawei-node2 kubeedge-scripts]# kubectl get pod -n kubeedge
NAME                         READY   STATUS    RESTARTS   AGE
cloudcore-7d5655d6f4-qjfmn   0/1     Pending   0          4s

kubectl describe pod -n kubeedge :

"1 node(s) had taint node-role.kubernetes.io/master: , that the pod didn't tolerate."

 Warning  FailedScheduling  30s (x3 over 2m58s)  default-scheduler  
0/1 nodes are available: 1 node(s) had taint node-role.kubernetes.io/master: ,
 that the pod didn't tolerate.

问题原因是:

使用kubeadm初始化的集群,出于安全考虑Pod不会被调度到Master Node上,也就是说Master Node不参与工作负载。

这里搭建的是测试环境可以使用下面的命令使Master Node参与工作负载:
k8s是master节点的hostname
允许master节点部署pod,使用命令如下:

kubectl taint nodes --all node-role.kubernetes.io/master-

接下来,在keadm reset --force 之后重新keadm beta init 便可使cloudcore的状态正常为Running。

以上是关于kubeedge: keadm 源码学习的主要内容,如果未能解决你的问题,请参考以下文章

使用Keadm进行部署KubeEdge

kubeedge源码分析课程学习

kubeedge源码分析

技术干货EdgeMesh使用和源码分析

(⊙o⊙)?原来边缘计算是这么开发的!

Sedna终身学习以及KubeEdge梳理