https://kubernetes.io/blog/2019/01/14/apiserver-dry-run-and-kubectl-diff/
Monday, January 14, 2019

Author: Antoine Pelisse (Google Cloud, @apelisse)

Declarative configuration management, also known as configuration-as-code, is one of the key strengths of Kubernetes. It allows users to commit the desired state of the cluster, and to keep track of the different versions, improve auditing and automation through CI/CD pipelines. The Apply working-group is working on fixing some of the gaps, and is happy to announce that Kubernetes 1.13 promoted server-side dry-run and kubectl diff to beta. These two features are big improvements for the Kubernetes declarative model.

Challenges

A few pieces are still missing in order to have a seamless declarative experience with Kubernetes, and we tried to address some of these:

  • While compilers and linters do a good job to detect errors in pull-requests for code, a good validation is missing for Kubernetes configuration files. The existing solution is to run kubectl apply --dry-run, but this runs a local dry-run that doesn't talk to the server: it doesn't have server validation and doesn't go through validating admission controllers. As an example, Custom resource names are only validated on the server so a local dry-run won't help.
  • It can be difficult to know how your object is going to be applied by the server for multiple reasons:
    • Defaulting will set some fields to potentially unexpected values,
    • Mutating webhooks might set fields or clobber/change some values.
    • Patch and merges can have surprising effects and result in unexpected objects. For example, it can be hard to know how lists are going to be ordered once merged.

The working group has tried to address these problems.

APIServer dry-run

APIServer dry-run was implemented to address these two problems:

  • it allows individual requests to the apiserver to be marked as "dry-run",
  • the apiserver guarantees that dry-run requests won't be persisted to storage,
  • the request is still processed as typical request: the fields are defaulted, the object is validated, it goes through the validation admission chain, and through the mutating admission chain, and then the final object is returned to the user as it normally would, without being persisted.

While dynamic admission controllers are not supposed to have side-effects on each request, dry-run requests are only processed if all admission controllers explicitly announce that they don't have any dry-run side-effects.

How to enable it

Server-side dry-run is enabled through a feature-gate. Now that the feature is Beta in 1.13, it should be enabled by default, but still can be enabled/disabled using kube-apiserver --feature-gates DryRun=true.

If you have dynamic admission controllers, you might have to fix them to:

  • Remove any side-effects when the dry-run parameter is specified on the webhook request,
  • Specify in the sideEffects field of the admissionregistration.k8s.io/v1beta1.Webhook object to indicate that the object doesn't have side-effects on dry-run (or at all).

How to use it

You can trigger the feature from kubectl by using kubectl apply --server-dry-run, which will decorate the request with the dryRun flag and return the object as it would have been applied, or an error if it would have failed.

Kubectl diff

APIServer dry-run is convenient because it lets you see how the object would be processed, but it can be hard to identify exactly what changed if the object is big. kubectl diff does exactly what you want by showing the differences between the current "live" object and the new "dry-run" object. It makes it very convenient to focus on only the changes that are made to the object, how the server has merged these and how the mutating webhooks affects the output.

How to use it

kubectl diff is meant to be as similar as possible to kubectl applykubectl diff -f some-resources.yaml will show a diff for the resources in the yaml file. One can even use the diff program of their choice by using the KUBECTL_EXTERNAL_DIFF environment variable, for example:

KUBECTL_EXTERNAL_DIFF=meld kubectl diff -f some-resources.yaml

What's next

The working group is still busy trying to improve some of these things:

  • Server-side apply is trying to improve the apply scenario, by adding owner semantics to fields! It's also going to improve support for CRDs and unions!
  • Some kubectl apply features are missing from diff and could be useful, like the ability to filter by label, or to display pruned resources.
  • Eventually, kubectl diff will use server-side apply!
Note: The flag kubectl apply --server-dry-run is deprecated in v1.18. Use the flag --dry-run=server for using server-side dry-run in kubectl apply and other subcommands.

[转帖]APIServer dry-run and kubectl diff的更多相关文章

  1. 2015年9月10-11日,杨学明老师《IPD DRY RUN》专题培训在武汉某上市企业成功举办!

    2015-9-10~11日,杨学明老师为武汉著名的光通信企业某上市公司实施了为期两天的“IPD DRY RUN”,开班前,该公司三个项目团队的负责人先后发言,烽火PMO部门领导和公开研发部网管系统的领 ...

  2. Gradle Goodness: Check Task Dependencies With a Dry Run

    We can run a Gradle build without any of the task actions being executed. This is a so-called dry ru ...

  3. ansible special topics

    1.加速模式运行playbook accelerate 对于使用ansible 1.5 及之后版本的用户,加速模式只在以下情况下有用处: (A) 管理红帽企业版 Linux 6 或者更早的那些依然使用 ...

  4. kubernetes之kubectl与YAML详解1

    k8s集群的日志,带有组件的信息,多看日志. kubectl命令汇总 kubectl命令汇总 kubectl命令帮助信息 [root@mcwk8s04 ~]# kubectl -h kubectl c ...

  5. kubectl简介

    kubectl简介 kubectl是操作k8s集群的命令行工具,安装在k8s的master节点,kubectl在$HOME/.kube目录中查找一个名为config的文件, 你可以通过设置Kubeco ...

  6. [k8s]Docker 用户使用 kubectl 命令指南-unkown排错(kubelet端口解析)

    参考:https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/ https://k8smeetup.github.io/docs/user-g ...

  7. kubectl kubernetes cheatsheet

    from : https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 PDF Link: cheatsheet-kubernetes-A4 ...

  8. Aggregated APIServer 构建云原生应用最佳实践

    作者 张鹏,腾讯云容器产品工程师,拥有多年云原生项目开发落地经验.目前主要负责腾讯云 TKE 云原生 AI 产品的开发工作. 谢远东,腾讯高级工程师,Kubeflow Member.Fluid(CNC ...

  9. Kubectl —— 基本命令

    Kubectl -- 基本命令 1.kubectl 基本命令 2.项目的生命周期 3.声明式管理方法 service的类型: ClusterIP:提供一个集群内部的虚拟IP以供Pod访问( servi ...

  10. 第九章 kubectl命令行工具使用详解

    1.管理k8s核心资源的三种基础方法 陈述式管理方法:主要依赖命令行CLI工具进行管理 声明式管理方法:主要依赖统一资源配置清单(manifest)进行管理 GUI式管理方法:主要依赖图形化操作界面( ...

随机推荐

  1. Java 打印Excel工作表

    示例要点 本文介绍如何通过Java程序打印Excel工作表.可通过以下方法打印: 默认打印机打印 指定打印机打印 程序环境 spire.xls.jar JDK版本要求1.6.0及以上的高版本 IDEA ...

  2. 数仓调优实践丨SQL改写消除相关子查询

    本文分享自华为云社区<[调优实践]SQL改写消除相关子查询>,作者: 门前一棵葡萄树 . 一.子查询 GaussDB(DWS)根据子查询在SQL语句中的位置把子查询分成了子查询.子链接两种 ...

  3. 避坑指南:关于SPDK问题分析过程

    [前言] 这是一次充满曲折与反转的问题分析,资料很少,代码很多,经验很少,概念很多,当内核态,用户态,DIF,LBA,大页内存,SGL,RDMA,NVME和SSD一起迎面而来的时候,问题是单点的意外, ...

  4. 互联网短平快下,DevCloud如何支撑软件开发的“转型”?

    摘要:2013年踏入互联网浪潮的张浩,在8年的软件开发中,一一经历了这三段"历史进程",感受到技术迭代更新背后的魅力. 互联网改变人们的衣食住行,也在悄然无声间为根植之上的软件行业 ...

  5. Hive查看表/分区更新时间

    1.查看分区 hive> show partitions table_name; 2.查看分区更新时间 获取hdfs路径 hive> desc formatted table_name; ...

  6. 开心档之MySQL 导出数据

    MySQL 导出数据 MySQL中你可以使用SELECT...INTO OUTFILE语句来简单的导出数据到文本文件上. 使用 SELECT ... INTO OUTFILE 语句导出数据 以下实例中 ...

  7. 火山引擎DataTester:企业如何使用A/B实验优化商业化能力

      商业化是企业将研发成果,如新产品.新技术.新服务等,转变成可盈利的商业化产品:整个流程中包含了研发.推广.服务,全程通过精细化管理运营.商业化的本质是流量的变现,而对企业而言,商业化链路的打磨至关 ...

  8. Chrome浏览器导出HTTPS证书

    点证书小锁 进入证书界面 到详情中,导出证书

  9. No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc

    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc ...

  10. 备份批处理文件 bat 生成 date 取年时,只取到周

    备份数据库文件时,发现MySQL备份生成的文件名为 [vipsoft_周三],发现是系统的日期格式问题.需调整日期格式,生成 [vipsoft_20220601.sql] mysqldump -uro ...