发布一个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源码分析,学习知其然,知其所以然
加qq群,请联系:
————————————————
type RestartOptions struct {//restart结构体
PrintFlags *genericclioptions.PrintFlags
ToPrinter func(string) (printers.ResourcePrinter, error)
Resources []string
Builder func() *resource.Builder
Restarter polymorphichelpers.ObjectRestarterFunc
Namespace string
EnforceNamespace bool
resource.FilenameOptions
genericclioptions.IOStreams
}
func NewRolloutRestartOptions(streams genericclioptions.IOStreams) *RestartOptions {
return &RestartOptions{//初始化结构体
PrintFlags: genericclioptions.NewPrintFlags("restarted").WithTypeSetter(scheme.Scheme),
IOStreams: streams,
}
}
//创建restart命令
func NewCmdRolloutRestart(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewRolloutRestartOptions(streams)//初始化结构体
validArgs := []string{"deployment", "daemonset", "statefulset"}
cmd := &cobra.Command{//创建cobra命令
Use: "restart RESOURCE",
DisableFlagsInUseLine: true,
Short: i18n.T("Restart a resource"),
Long: restartLong,
Example: restartExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, cmd, args))//准备
cmdutil.CheckErr(o.Validate())//校验
cmdutil.CheckErr(o.RunRestart())//运行
},
ValidArgs: validArgs,//有效参数
}
usage := "identifying the resource to get from a server."
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)//文件选项
o.PrintFlags.AddFlags(cmd)//打印选项
return cmd
}
//准备函数
func (o *RestartOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
o.Resources = args//设置资源
o.Restarter = polymorphichelpers.ObjectRestarterFn//设置Restarter函数
var err error
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()//设置namespace和enforceNamespace
if err != nil {
return err
}
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {//print flag 转printer函数
o.PrintFlags.NamePrintFlags.Operation = operation
return o.PrintFlags.ToPrinter()
}
o.Builder = f.NewBuilder//设置builder
return nil
}
//校验
func (o *RestartOptions) Validate() error {
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {//资源和文件至少有一个
return fmt.Errorf("required resource not specified")
}
return nil
}
//运行
func (o RestartOptions) RunRestart() error {
r := o.Builder().
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
NamespaceParam(o.Namespace).DefaultNamespace().
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
ResourceTypeOrNameArgs(true, o.Resources...).
ContinueOnError().
Latest().
Flatten().
Do()//构造result对象
if err := r.Err(); err != nil {
return err
}
allErrs := []error{}
infos, err := r.Infos()//获取info对象
if err != nil {
// restore previous command behavior where
// an error caused by retrieving infos due to
// at least a single broken object did not result
// in an immediate return, but rather an overall
// aggregation of errors.
allErrs = append(allErrs, err)
}
for _, patch := range set.CalculatePatches(infos, scheme.DefaultJSONEncoder(), set.PatchFn(o.Restarter)) {//计算info补丁,并遍历
info := patch.Info
if patch.Err != nil {//补丁有错误,append错误继续
resourceString := info.Mapping.Resource.Resource
if len(info.Mapping.Resource.Group) > 0 {
resourceString = resourceString + "." + info.Mapping.Resource.Group
}
allErrs = append(allErrs, fmt.Errorf("error: %s %q %v", resourceString, info.Name, patch.Err))
continue
}
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {//如果补丁为空,则append错误
allErrs = append(allErrs, fmt.Errorf("failed to create patch for %v: empty patch", info.Name))
}
obj, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch, nil)//用helper应用补丁到服务端
if err != nil {
allErrs = append(allErrs, fmt.Errorf("failed to patch: %v", err))
continue
}
info.Refresh(obj, true)//刷新obj对象
printer, err := o.ToPrinter("restarted")//printflag转printer
if err != nil {
allErrs = append(allErrs, err)
continue
}
if err = printer.PrintObj(info.Object, o.Out); err != nil {//打印结果
allErrs = append(allErrs, err)
}
}
return utilerrors.NewAggregate(allErrs)
}