综合技术

Declarative Configuration for kubeadm — #HeptioProTip

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.

阅读原文...

Avatar

PostgreSQL Sample Database

上一篇

Voyage into the World of Serverless Computing — with a 135-year-old Shipping Company

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Declarative Configuration for kubeadm — #HeptioProTip

长按储存图像,分享给朋友