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:
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:
endpoints: #assuming default port
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.【阅读原文...】