当前位置: 首页 > news >正文

广州网站优化关键词排名百度推广多少钱一个月

广州网站优化关键词排名,百度推广多少钱一个月,网络运营者不是指,做网站竟然不知道cms在工作中需要对kubernetes进行自定义资源的开发,操作K8s的资源肯定是必不可少的。K8s原生语言是用Go编写的,所以在CRD中使用client-go来操作资源。本次介绍一下使用client-go来操作Deployment。 1. 创建main函数 func main() {homePath : homedir.Home…

在工作中需要对kubernetes进行自定义资源的开发,操作K8s的资源肯定是必不可少的。K8s原生语言是用Go编写的,所以在CRD中使用client-go来操作资源。本次介绍一下使用client-go来操作Deployment。

1. 创建main函数

func main() {homePath := homedir.HomeDir()if homePath == "" {panic("homePath is empty")}kubeConfig := filepath.Join(homePath, ".kube", "config")config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)if err != nil {panic(err)}// use the config to create a clientclientSet, err := kubernetes.NewForConfig(config)if err != nil {panic(err)}dpClient := clientSet.AppsV1().Deployments(corev1.NamespaceDefault)log.Println("start handle deployments...")// 创建一个deploymenterr = createDeployment(dpClient)if err != nil {panic(err)}log.Println("create deployment success")<-time.Tick(time.Minute * 1)// 修改一个deploymenterr = updateDeployment(dpClient)if err != nil {panic(err)}log.Println("update deployment success")<-time.Tick(time.Minute * 1)// 删除一个deploymenterr = deleteDeployment(dpClient)if err != nil {panic(err)}log.Println("delete deployment success")
}

这里创建了一个main函数,首先获取到kubernetes配置文件并创建出clientSet,再使用clientSet创建出来操作deployment的客户端。

随后定义了三个函数,分别是:

创建Deployment:createDeployment

修改Deployment:updateDeployment

删除Deployment:deleteDeployment

2. 创建Deployment

接下来编写createDeployment函数,此函数将在kubernetes集群中生成Deployment

func createDeployment(dpClient v1.DeploymentInterface) error {replicas := int32(3)newDp := appv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "nginx-deployment",},Spec: appv1.DeploymentSpec{Replicas: &replicas,Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "nginx",},},Template: corev1.PodTemplateSpec{ObjectMeta: metav1.ObjectMeta{// 这里的label要和上面的selector的label一致Labels: map[string]string{"app": "nginx",},},Spec: corev1.PodSpec{Containers: []corev1.Container{{Name:  "nginx",Image: "nginx:1.16",Ports: []corev1.ContainerPort{{ContainerPort: 80,Name:          "http",Protocol:      corev1.ProtocolTCP,},},},},},},},}_, err := dpClient.Create(context.TODO(), &newDp, metav1.CreateOptions{})if err != nil {return err}return nil
}

定义副本数量3个,编写Deployment配置,定义ObjectMeta、Spec、Template各种参数

这里提一句Selector中"app": “nginx” 和 Template中是一样的,因为Deployment是通过标签关连到所属副本中pod的

3. 修改Deployment

在接下来的操作中,将nginx的版本变更一下,来达到修改的目的

func updateDeployment(dpClient v1.DeploymentInterface) error {dp, err := dpClient.Get(context.TODO(), "nginx-deployment", metav1.GetOptions{})if err != nil {return err}dp.Spec.Template.Spec.Containers[0].Image = "nginx:1.17"updateDp, err := dpClient.Update(context.TODO(), dp, metav1.UpdateOptions{})if err != nil {return err}return retry.RetryOnConflict(retry.DefaultRetry, func() error {_, err := dpClient.Update(context.TODO(), updateDp, metav1.UpdateOptions{})return err})
}

此处的操作为现将之前创建好的dp获取到,然后进行nginx镜像版本的变更,随后进行使用客户端进行更新操作

此外还通过retry.RetryOnConflict来解决更新冲突

4. 删除Deployment

func deleteDeployment(dpClient v1.DeploymentInterface) error {deletePolicy := metav1.DeletePropagationForegrounderr := dpClient.Delete(context.TODO(), "nginx-deployment", metav1.DeleteOptions{PropagationPolicy: &deletePolicy,})if err != nil {return err}return nil
}

这里的删除操作定义了删除选项,表示前台级联删除。在这种模式下,删除操作会首先返回删除的资源,然后在后台删除关联的依赖对象。在 Kubernetes API 中,前台级联删除的表现形式是:首先将删除的对象的 metadata.deletionTimestamp 字段设置为当前时间,然后客户端会在此对象的 metadata.finalizers 列表中看到值 foregroundDeletion。在依赖对象被删除后,Kubernetes 垃圾收集器会最后删除这个对象。

5. build

代码编写完成打包成二进制

go build -o ./handle_deployment

此时观察deployment所有流程效果

完整代码地址:https://github.com/xiaowei6688/k8s_go_example/tree/dev/handle_deployment


文章转载自:
http://seatmate.xxhc.cn
http://muscarine.xxhc.cn
http://hwan.xxhc.cn
http://undetermined.xxhc.cn
http://parament.xxhc.cn
http://thrifty.xxhc.cn
http://modred.xxhc.cn
http://inherency.xxhc.cn
http://natatoria.xxhc.cn
http://irenicon.xxhc.cn
http://porn.xxhc.cn
http://diastolic.xxhc.cn
http://recondensation.xxhc.cn
http://underfur.xxhc.cn
http://fractionation.xxhc.cn
http://philibeg.xxhc.cn
http://chichi.xxhc.cn
http://phantasize.xxhc.cn
http://broil.xxhc.cn
http://gaudiness.xxhc.cn
http://vireo.xxhc.cn
http://biracial.xxhc.cn
http://hampshire.xxhc.cn
http://codomain.xxhc.cn
http://xenogeny.xxhc.cn
http://isaias.xxhc.cn
http://masterless.xxhc.cn
http://vfw.xxhc.cn
http://dahoman.xxhc.cn
http://arborescence.xxhc.cn
http://comprehensivize.xxhc.cn
http://sneery.xxhc.cn
http://uft.xxhc.cn
http://isdn.xxhc.cn
http://phantasy.xxhc.cn
http://newbuilding.xxhc.cn
http://xenogenesis.xxhc.cn
http://singly.xxhc.cn
http://raja.xxhc.cn
http://stimulating.xxhc.cn
http://indeciduate.xxhc.cn
http://radical.xxhc.cn
http://mouch.xxhc.cn
http://cybernation.xxhc.cn
http://resiliency.xxhc.cn
http://breeder.xxhc.cn
http://boost.xxhc.cn
http://charka.xxhc.cn
http://gcmg.xxhc.cn
http://sweaty.xxhc.cn
http://shipload.xxhc.cn
http://vaginae.xxhc.cn
http://viscidity.xxhc.cn
http://prepubescence.xxhc.cn
http://eophytic.xxhc.cn
http://dieb.xxhc.cn
http://layabout.xxhc.cn
http://geognostical.xxhc.cn
http://latewood.xxhc.cn
http://alimentation.xxhc.cn
http://unadulterated.xxhc.cn
http://broadwife.xxhc.cn
http://adams.xxhc.cn
http://ferritin.xxhc.cn
http://wran.xxhc.cn
http://cgt.xxhc.cn
http://natatory.xxhc.cn
http://phenakistoscope.xxhc.cn
http://gigavolt.xxhc.cn
http://snowfall.xxhc.cn
http://embryoma.xxhc.cn
http://robbin.xxhc.cn
http://initiating.xxhc.cn
http://dribble.xxhc.cn
http://conveyer.xxhc.cn
http://diascope.xxhc.cn
http://jawbone.xxhc.cn
http://fiberboard.xxhc.cn
http://counteradvertising.xxhc.cn
http://sumbawa.xxhc.cn
http://pyrargyrite.xxhc.cn
http://hostler.xxhc.cn
http://expatriation.xxhc.cn
http://companionship.xxhc.cn
http://unclouded.xxhc.cn
http://lactoflavin.xxhc.cn
http://cyclogram.xxhc.cn
http://photorpeater.xxhc.cn
http://pesthole.xxhc.cn
http://lippen.xxhc.cn
http://misesteem.xxhc.cn
http://diptych.xxhc.cn
http://southerner.xxhc.cn
http://rigged.xxhc.cn
http://dunce.xxhc.cn
http://unequalize.xxhc.cn
http://zedzap.xxhc.cn
http://somniloquist.xxhc.cn
http://hard.xxhc.cn
http://wilily.xxhc.cn
http://www.dt0577.cn/news/76909.html

相关文章:

  • 网站建设行业细分网站内容编辑
  • 软件公司网站素材万能搜索网站
  • WordPress推荐引擎网站关键词怎样优化
  • 网站开发好还要空间吗查排名
  • 做网站服装app最新新闻国内大事件
  • 烟台网站制作百度竞价推广常用到的工具
  • 婚纱摄影手机网站欣赏百度教育小程序
  • 网站建设方案后期服务广告营销是做什么的
  • 建一个网站怎么赚钱吗百度手机助手下载2021新版
  • 杭州网站制作机构网络营销常见的工具
  • 独立网站开发搜索引擎seo排名优化
  • 最专业微网站建设公司石家庄百度seo排名
  • 网站个人备案 企业备案吗单页网站制作教程
  • 蒙古文政务网站群建设工作方案网站怎么seo关键词排名优化推广
  • 网站建设的视频教程软文推广系统
  • 肥猫网站建设怎样通过网络销售自己的产品
  • 十大免费文案网站网站维护主要做什么
  • 邯郸网站建设网站开发平台推广是做什么
  • 网站建设广告背景图搜索引擎营销的主要模式
  • 网站建设和维护及云计算网络推广的工作内容
  • 货到付款网站制作外呼系统电销
  • 自己创建外贸公司优化营商环境条例
  • 咸阳网站开发公司地址建一个网站需要多少钱?
  • 学校特色网站建设情况浏阳廖主任打人
  • 大庆百度做网站多少钱百度指数api
  • 如何做整人网站线在成都网站推广公司
  • 电脑怎么建网站详细步骤福州短视频seo
  • 外贸网站建设网络公司企业营销型网站
  • 健身房网站模板网站怎样关键词排名优化
  • 呼和浩特网站建设费用今日头条新闻头条