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

介绍主要的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等。

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

type ConfigMapOpts struct {//选项结构体
CreateSubcommandOptions *CreateSubcommandOptions
}
//创建configmap cobra命令
func NewCmdCreateConfigMap(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := &ConfigMapOpts{//初始化选项结构体
CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
}

cmd := &cobra.Command{//创建cobra命令
Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run]",
DisableFlagsInUseLine: true,
Aliases: []string{"cm"},
Short: i18n.T("Create a configmap from a local file, directory or literal value"),
Long: configMapLong,
Example: configMapExample,
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.ConfigMapV1GeneratorName)//创建generator选项
cmd.Flags().StringSlice("from-file", []string{}, "Key file can be specified using its file path, in which case file basename will be used as configmap key, or optionally with a key and file path, in which case the given key will be used. Specifying a directory will iterate each named file in the directory whose basename is a valid configmap key.")//创建from-file选项
cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)")//创建from-literal选项
cmd.Flags().String("from-env-file", "", "Specify the path to a file to read lines of key=val pairs to create a configmap (i.e. a Docker .env file).")//创建from-env-file选项
cmd.Flags().Bool("append-hash", false, "Append a hash of the configmap to its name.")//创建append-hash选项
return cmd
}
//做一些准备工作
func (o *ConfigMapOpts) 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.ConfigMapV1GeneratorName://获取generator选项并判断
generator = &generateversioned.ConfigMapGeneratorV1{//构造generator对象
Name: name,
FileSources: cmdutil.GetFlagStringSlice(cmd, "from-file"),
LiteralSources: cmdutil.GetFlagStringArray(cmd, "from-literal"),
EnvFileSource: cmdutil.GetFlagString(cmd, "from-env-file"),
AppendHash: cmdutil.GetFlagBool(cmd, "append-hash"),
}
default:
return errUnsupportedGenerator(cmd, generatorName)
}

return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubCommandoption的complete
}

其他和上一个命令一样,不做介绍