Skip to content

antony@notes:~/kubernetes$ cat "Kubernetes-Init-with-Config.yaml.md"

Kubernetes Init with Config.yaml

2022-09-13· kubernetes ·系統工程

Kubernetes Init with Config.yaml

Prepare

To print the defaults for “init” actions use the following commands:

$ kubeadm config print init-defaults > init-config.yaml

編輯 init-config.yaml

$ nano init-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3
#bootstrapTokens:                                       # remove
#- groups:                                              # remove
#  - system:bootstrappers:kubeadm:default-node-token    # remove
#  token: abcdef.0123456789abcdef                       # remove
#  ttl: 24h0m0s                                         # remove
#  usages:                                              # remove
#  - signing                                            # remove
#  - authentication                                     # remove
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 120.96.143.76                       # change from Master node IP
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///run/crio/crio.sock                 # change from CRI-O Unix Socket
  imagePullPolicy: IfNotPresent
  name: c3-m1                                           # change from Master node hsotname
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: bobo                                        # set your clusterName
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.k8s.io
kind: ClusterConfiguration
kubernetesVersion: 1.25.0
networking:
  dnsDomain: k8s.bobo.org                                 # DNS domain used by Kubernetes Services.
  podSubnet: 10.244.0.0/16                                # the subnet used by Pods.
  serviceSubnet: 10.98.0.0/24                             # subnet used by Kubernetes Services.
scheduler: {}
  • nodeRegistration.taints,taints specifies the taints the Node API object should be registered with. If this field is unset, i.e. nil, in the kubeadm init process it will be defaulted with a control-plane taint for control-plane nodes. If you don’t want to taint your control-plane node, set this field to an empty list, i.e. taints: [] in the YAML file. This field is solely used for Node registration.

初始化 K8S

$ sudo kubeadm init --config=init-config.yaml
  • --config string ,Path to a kubeadm configuration file.
  • When executing kubeadm init with the --config option, the following configuration types could be used:
    • InitConfiguration
    • ClusterConfiguration
    • KubeProxyConfiguration
    • KubeletConfiguration
  • but only one between InitConfiguration and ClusterConfiguration is mandatory.
  • If some configuration types are not provided, or provided only partially, kubeadm will use default values

References