发布一个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源码分析,学习知其然,知其所以然
————————————————
func NewCmdCreateSecret(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{//创建secret cobra命令
Use: "secret",
Short: i18n.T("Create a secret using specified subcommand"),
Long: "Create a secret using specified subcommand.",
Run: cmdutil.DefaultSubCommandRun(ioStreams.ErrOut),
}
cmd.AddCommand(NewCmdCreateSecretDockerRegistry(f, ioStreams))//添加docker-registry子命令
cmd.AddCommand(NewCmdCreateSecretTLS(f, ioStreams))//添加tls子命令
cmd.AddCommand(NewCmdCreateSecretGeneric(f, ioStreams))//添加generic子命令
return cmd
}
func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := &SecretDockerRegistryOpts{
CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
}
cmd := &cobra.Command{//创建create secret docker-registry命令
Use: "docker-registry NAME --docker-username=user --docker-password=password --docker-email=email [--docker-server=string] [--from-literal=key1=value1] [--dry-run]",
DisableFlagsInUseLine: true,
Short: i18n.T("Create a secret for use with a Docker registry"),
Long: secretForDockerRegistryLong,
Example: secretForDockerRegistryExample,
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)//添加校验选项
cmdutil.AddGeneratorFlags(cmd, generateversioned.SecretForDockerRegistryV1GeneratorName)//添加generater选项
cmd.Flags().String("docker-username", "", i18n.T("Username for Docker registry authentication"))//添加docker-username选项
cmd.MarkFlagRequired("docker-username")//标记为必须
cmd.Flags().String("docker-password", "", i18n.T("Password for Docker registry authentication"))//添加docker-password选项
cmd.MarkFlagRequired("docker-password")
cmd.Flags().String("docker-email", "", i18n.T("Email for Docker registry"))//添加docker-email选项
cmd.Flags().String("docker-server", "https://index.docker.io/v1/", i18n.T("Server location for Docker registry"))//添加docker-server选项
cmd.Flags().Bool("append-hash", false, "Append a hash of the secret to its name.")//添加append-hash选项
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.")//添加from-file选项
return cmd
}
func NewCmdCreateSecretTLS(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := &SecretTLSOpts{
CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
}
cmd := &cobra.Command{//创建create secret tls命令
Use: "tls NAME --cert=path/to/cert/file --key=path/to/key/file [--dry-run]",
DisableFlagsInUseLine: true,
Short: i18n.T("Create a TLS secret"),
Long: secretForTLSLong,
Example: secretForTLSExample,
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.SecretForTLSV1GeneratorName)//添加generator选项
cmd.Flags().String("cert", "", i18n.T("Path to PEM encoded public key certificate."))//添加cert选项
cmd.Flags().String("key", "", i18n.T("Path to private key associated with given certificate."))//添加key选项
cmd.Flags().Bool("append-hash", false, "Append a hash of the secret to its name.")//添加append-hash选项
return cmd
}
//docker-registry命令准备函数
func (o *SecretDockerRegistryOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
name, err := NameFromCommandArgs(cmd, args)//户籍去资源名称
if err != nil {
return err
}
fromFileFlag := cmdutil.GetFlagStringSlice(cmd, "from-file")//获取from-file选项值
if len(fromFileFlag) == 0 {//如果from-file值为空,则docker-username,docker-password,docker-server为必须选项
requiredFlags := []string{"docker-username", "docker-password", "docker-server"}
for _, requiredFlag := range requiredFlags {
if value := cmdutil.GetFlagString(cmd, requiredFlag); len(value) == 0 {
return cmdutil.UsageErrorf(cmd, "flag %s is required", requiredFlag)
}
}
}
var generator generate.StructuredGenerator
switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
case generateversioned.SecretForDockerRegistryV1GeneratorName://获取generator选项并判断是否有效
generator = &generateversioned.SecretForDockerRegistryGeneratorV1{//构造generator
Name: name,
Username: cmdutil.GetFlagString(cmd, "docker-username"),
Email: cmdutil.GetFlagString(cmd, "docker-email"),
Password: cmdutil.GetFlagString(cmd, "docker-password"),
Server: cmdutil.GetFlagString(cmd, "docker-server"),
AppendHash: cmdutil.GetFlagBool(cmd, "append-hash"),
FileSources: cmdutil.GetFlagStringSlice(cmd, "from-file"),
}
default:
return errUnsupportedGenerator(cmd, generatorName)
}
return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行createSubCommandOption的complete
}
func (o *SecretTLSOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {//运行tls命令的complete
name, err := NameFromCommandArgs(cmd, args)//获取名称
if err != nil {
return err
}
requiredFlags := []string{"cert", "key"}//判断必须选项是否为空
for _, requiredFlag := range requiredFlags {
if value := cmdutil.GetFlagString(cmd, requiredFlag); len(value) == 0 {
return cmdutil.UsageErrorf(cmd, "flag %s is required", requiredFlag)
}
}
var generator generate.StructuredGenerator
switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
case generateversioned.SecretForTLSV1GeneratorName://获取generator选项并判断
generator = &generateversioned.SecretForTLSGeneratorV1{//构造generator
Name: name,
Key: cmdutil.GetFlagString(cmd, "key"),
Cert: cmdutil.GetFlagString(cmd, "cert"),
AppendHash: cmdutil.GetFlagBool(cmd, "append-hash"),
}
default:
return errUnsupportedGenerator(cmd, generatorName)
}
return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)//运行CreateSubCommandOption的complete
}
func NewCmdCreateSecretGeneric(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := &SecretGenericOpts{
CreateSubcommandOptions: NewCreateSubcommandOptions(ioStreams),
}
cmd := &cobra.Command{//创建create secret generic命令
Use: "generic NAME [--type=string] [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run]",
DisableFlagsInUseLine: true,
Short: i18n.T("Create a secret from a local file, directory or literal value"),
Long: secretLong,
Example: secretExample,
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.SecretV1GeneratorName)//创建generator选项
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.")//创建from-file选项
cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in secret (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 secret (i.e. a Docker .env file).")//创建from-env-file选项
cmd.Flags().String("type", "", i18n.T("The type of secret to create"))//创建type选项
cmd.Flags().Bool("append-hash", false, "Append a hash of the secret to its name.")//创建append-hash选项
return cmd
}
func (o *SecretGenericOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {//运行generic命令complete方法
name, err := NameFromCommandArgs(cmd, args)//获取资源名称
if err != nil {
return err
}
var generator generate.StructuredGenerator
switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
case generateversioned.SecretV1GeneratorName://获取generator并判断
generator = &generateversioned.SecretGeneratorV1{//构造generator
Name: name,
Type: cmdutil.GetFlagString(cmd, "type"),
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
}
run方法和前一个命令逻辑一样,这里不再列出