Declarative Configuration for kubeadm — #HeptioProTip

综合技术 2017-12-13

In this particular protip, we’ll be focusing on kubeadm , a bootstrapping tool for Kubernetes clusters.

Photo Credit: David Cohen

If you’ve ever found yourself wanting a more declarative way of specifying bootstrap parameters during kubeadm init , kubeadm has an alpha feature for that! This feature allows you to use a configuration file to set parameters, as opposed to command-line flags.

What are the benefits? A config file enables repeatable, predictable cluster provisioning — unlike the sprawling fire of command-line flags, which are especially prone to typos and other errors.

For example, if you wanted to bootstrap a cluster with the following settings:

  • Pod networking CIDR range
  • Non-default node name
  • Kubernetes version 1.7.4
  • Port where the API server will be listening

With traditional kubeadm command-line flags, your command would look like this:

kubeadm init --apiserver-bind-port 10443 --node-name master-001 --pod-network-cidr 192.168.1.0/24 --kubernetes-version 1.7.4

As your use case gets more complex, those command line flags and arguments begin to get unwieldy. However, with the alpha feature we mentioned, you can define the same configurations in a YAML file, as follows:


apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
api:
bindPort: 10443
networking:
podSubnet: 192.168.1.0/24
kubernetesVersion: 1.7.4
nodeName: master-001

A YAML file makes the your kubeadm’s configuration easier to read and update. It also makes your kubeadm init command a lot simpler. Once you’re ready to provision your cluster, simply run the following command:

kubeadm init --config=confile.filename.yaml

Now let’s examine another common use case: leveraging an external etcd cluster. Usually, this requires specifying endpoints via the command line, which can be cumbersome.

However, with a config file this is much more manageable, and an easy, natural extension of the previous example file:


apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
api:
bindPort: 10443
networking:
podSubnet: 192.168.1.0/24
kubernetesVersion: 1.7.4
nodeName: master-001
etcd:
endpoints: #assuming default port
http://etcd-1
http://etcd-2
http://etcd-3

This config file can be referenced with the --config flag of the kubeadm init command, just like in the previous example.

This sort of workflow — with your cluster bootstrap configuration neatly in one place — lends itself well to peer and code reviews, version control, and in more advanced use cases, even automated cluster provisioning (CI/CD).

Hope you enjoyed this #HeptioProTip! Follow @heptio for more tips and tricks.

责编内容by:Heptio (源链)。感谢您的支持!

您可能感兴趣的

AWS 中国区部署 Kubernetes 1.9.3 本文档初版写于 2018 年 6 月, kops release 最新版本为 1.9.1 0. 目标和背景 即刻技术团队一直在实践 DevOps 文化...
Kubernetes – Scheduling and Multiple Availability ... The Kubernetes Scheduler is a very important part of the overall platform but its functionality and ...
How to Make a Responsive HTML5 Bootstrap Landing P... When you’re getting ready to launch a new website, a product, or a service, you need a dedicated pl...
Kubernetes Pod无法挂载ceph RBD存储卷的临时解决方法... 所有涉及到存储的地方都是极易出现“坑”的地方,Kubernetes也不例外。 一、问题起因 问题始于昨天升级一个stateful service的操作。该service下的Pod挂载了...
Bootstrap 模态框多次显示后台会提交多次BUG... 模态框 Bootstrap Modal Bootstrap 的模态框使用Bootstrap 的前端应该都接触过。 本文记录一下今天使用时遇到的 BUG,以便以后查阅和...