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 【阅读原文】。感谢您的支持!

您可能感兴趣的

Docker Desktop添加对Kubernetes的支持 Docker在其stable频道发布了Windows和Mac平台下Docker Desktop 对Kubernetes的支持 。Kubernetes也得到了Docker Enterprise的支持,允许我们将相同的镜像部署到两个系统...
Why Bootstrap? Because You Can’t Succeed Unl... Opinions expressed by Entrepreneur contributors are their own. Startup culture is all about the hustle. Fr...
Cockpit148 Cockpit is the modern Linux admin interface . We release regularly. Here are the release notes from version 148. Sup...
Whitespaces and strings in Bash Last week at work I was working on a bash script, part of which needed to get the status of a Kubernetes node. Specifica...
把我的个人网站推倒重来(Part 2 – 用 Bootstrap 做移动网页)... 配置好 Harp 做静态网站构建后,就可以开始做网页了。上一个版本的个人网站样式是我自己设计的,当年用的还是 Macromedia/Adobe Fireworks,做出来一个 PNG 文件然后导出为不同的小图片。这次我也有考虑过要不要自己...