发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.csdn.net/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.csdn.net/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件

第四个课程发布:https://edu.csdn.net/course/detail/28488

本课程将详细介绍k8s所有命令,以及命令的go源码分析,学习知其然,知其所以然
————————————————

//create service cobra命令
func NewCmdCreateService(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	cmd := &cobra.Command{//创建cobra命令
		Use:     "service",
		Aliases: []string{"svc"},
		Short:   i18n.T("Create a service using specified subcommand."),
		Long:    "Create a service using specified subcommand.",
		Run:     cmdutil.DefaultSubCommandRun(ioStreams.ErrOut),
	}
	cmd.AddCommand(NewCmdCreateServiceClusterIP(f, ioStreams))//clusterip子命令
	cmd.AddCommand(NewCmdCreateServiceNodePort(f, ioStreams))//NodePort子命令
	cmd.AddCommand(NewCmdCreateServiceLoadBalancer(f, ioStreams))//loadBlancer子命令
	cmd.AddCommand(NewCmdCreateServiceExternalName(f, ioStreams))//externalName子命令

	return cmd
}
type ServiceClusterIPOpts struct {//xlusterip选项
	CreateSubcommandOptions *CreateSubcommandOptions
}
//创建create svc clusterip命令
func NewCmdCreateServiceClusterIP(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	options := &ServiceClusterIPOpts{//初始化选项
		CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
	}

	cmd := &cobra.Command{//创建cobra命令
		Use:                   "clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Create a ClusterIP service."),
		Long:                  serviceClusterIPLong,
		Example:               serviceClusterIPExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(options.Complete(f, cmd, args))//准备运行
			cmdutil.CheckErr(options.Run())//运行命令
		},
	}

	options.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)//设置print flag选项

	cmdutil.AddApplyAnnotationFlags(cmd)//设置save-config选项
	cmdutil.AddValidateFlags(cmd)//设置validate选项
	cmdutil.AddGeneratorFlags(cmd, generateversioned.ServiceClusterIPGeneratorV1Name)//设置generator选项
	addPortFlags(cmd)//设置port选项
	cmd.Flags().String("clusterip", "", i18n.T("Assign your own ClusterIP or set to 'None' for a 'headless' service (no loadbalancing)."))//设置clusterIp选项
	return cmd
}
//运行clusterip complete方法
func (o *ServiceClusterIPOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)//获取资源名称
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceClusterIPGeneratorV1Name://获取generator选项,并判断
		generator = &generateversioned.ServiceCommonGeneratorV1{//构造generator对象
			Name:      name,
			TCP:       cmdutil.GetFlagStringSlice(cmd, "tcp"),
			Type:      v1.ServiceTypeClusterIP,
			ClusterIP: cmdutil.GetFlagString(cmd, "clusterip"),
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubcommandOption的complete
}
type ServiceNodePortOpts struct {//nodePort选项
	CreateSubcommandOptions *CreateSubcommandOptions
}
//创建nodeport命令
func NewCmdCreateServiceNodePort(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	options := &ServiceNodePortOpts{//初始化选项
		CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
	}

	cmd := &cobra.Command{//创建cobra命令
		Use:                   "nodeport NAME [--tcp=port:targetPort] [--dry-run]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Create a NodePort service."),
		Long:                  serviceNodePortLong,
		Example:               serviceNodePortExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(options.Complete(f, cmd, args))//准备运行
			cmdutil.CheckErr(options.Run())//运行命令
		},
	}

	options.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)//设置print flag选项

	cmdutil.AddApplyAnnotationFlags(cmd)//设置save-config选项
	cmdutil.AddValidateFlags(cmd)//设置validate选项
	cmdutil.AddGeneratorFlags(cmd, generateversioned.ServiceNodePortGeneratorV1Name)//设置generator选项
	cmd.Flags().Int("node-port", 0, "Port used to expose the service on each node in a cluster.")//设置node-prot选项
	addPortFlags(cmd)//设置tcp选项
	return cmd
}
//运行nodeport的complete方法
func (o *ServiceNodePortOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)//获取名称
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceNodePortGeneratorV1Name://获取generator选项并判断
		generator = &generateversioned.ServiceCommonGeneratorV1{//构造generator对象
			Name:      name,
			TCP:       cmdutil.GetFlagStringSlice(cmd, "tcp"),
			Type:      v1.ServiceTypeNodePort,
			ClusterIP: "",
			NodePort:  cmdutil.GetFlagInt(cmd, "node-port"),
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubcommandOption的complete方法
}
type ServiceLoadBalancerOpts struct {//loadbalancer选项
	CreateSubcommandOptions *CreateSubcommandOptions
}
//创建loadbalancer命令
func NewCmdCreateServiceLoadBalancer(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	options := &ServiceLoadBalancerOpts{//初始化选项
		CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
	}

	cmd := &cobra.Command{//创建cobra命令
		Use:                   "loadbalancer NAME [--tcp=port:targetPort] [--dry-run]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Create a LoadBalancer service."),
		Long:                  serviceLoadBalancerLong,
		Example:               serviceLoadBalancerExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(options.Complete(f, cmd, args))//准备运行
			cmdutil.CheckErr(options.Run())//运行命令
		},
	}

	options.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)//设置print选项

	cmdutil.AddApplyAnnotationFlags(cmd)//设置save-config选项
	cmdutil.AddValidateFlags(cmd)//设置validate选项
	cmdutil.AddGeneratorFlags(cmd, generateversioned.ServiceLoadBalancerGeneratorV1Name)//设置generator选项
	addPortFlags(cmd)//设置tcp选项
	return cmd
}
//运行loadbalancer complete方法
func (o *ServiceLoadBalancerOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)//获取名称
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceLoadBalancerGeneratorV1Name://获取generator选项并判读昂
		generator = &generateversioned.ServiceCommonGeneratorV1{//构造generator对象
			Name:      name,
			TCP:       cmdutil.GetFlagStringSlice(cmd, "tcp"),
			Type:      v1.ServiceTypeLoadBalancer,
			ClusterIP: "",
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubCommandOption complete方法
}
type ServiceExternalNameOpts struct {//externalname选项
	CreateSubcommandOptions *CreateSubcommandOptions
}
//构造externalname命令
func NewCmdCreateServiceExternalName(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	options := &ServiceExternalNameOpts{//初始化选项
		CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
	}

	cmd := &cobra.Command{//创建cobra命令
		Use:                   "externalname NAME --external-name external.name [--dry-run]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Create an ExternalName service."),
		Long:                  serviceExternalNameLong,
		Example:               serviceExternalNameExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(options.Complete(f, cmd, args))//准备运行
			cmdutil.CheckErr(options.Run())//运行命令
		},
	}

	options.CreateSubcommandOptions.PrintFlags.AddFlags(cmd)//设置print选项

	cmdutil.AddApplyAnnotationFlags(cmd)//设置save-config选项
	cmdutil.AddValidateFlags(cmd)//设置validate选项
	cmdutil.AddGeneratorFlags(cmd, generateversioned.ServiceExternalNameGeneratorV1Name)//设置generator选项
	addPortFlags(cmd)//设置tcp选项
	cmd.Flags().String("external-name", "", i18n.T("External name of service"))//设置externalname选项
	cmd.MarkFlagRequired("external-name")//external-name必须
	return cmd
}
//运行externalname complete方法
func (o *ServiceExternalNameOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)//获取名称
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceExternalNameGeneratorV1Name://获取generator选项并判断
		generator = &generateversioned.ServiceCommonGeneratorV1{//构造generator对象
			Name:         name,
			Type:         v1.ServiceTypeExternalName,
			ExternalName: cmdutil.GetFlagString(cmd, "external-name"),
			ClusterIP:    "",
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubCommandOption complete方法
}

 

其他和上一个源码一样,不做介绍

 

 

 

 

 

 

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐