kubeadm init --apiserver-advertise-address flag equivalent in config file
Asked Answered
C

1

6

I need to initialize my kubernetes cluster using a kubeadm config file due to some extra arguments that I need to pass, which are not directly available to kubeadm init.

I did create a config file and it works fine. I went throgh the documentation of the kubeadm config file but still not able to get which option is equivalent to the command line flag --apiserver-advertise-address

My kubeadm version is 1.15.7

This is my current config: Commented out lines are the options which I already tried but dosen't seem to work.

#apiVersion: kubeadm.k8s.io/v1beta2
#kind: InitConfiguration
#APIEndpoint:
#  advertiseAddress: "192.168.224.22"
#  bindPort: 6443
#controlPlaneEndpoint: "192.168.224.22:6443"
apiServer:
  advertiseAddress: "192.168.224.22"
  extraArgs:
    authorization-mode: Node,RBAC
#    advertise-address: 192.168.224.22
    authentication-token-webhook-config-file: /webhook/webhook-config.yaml
  extraVolumes:
  - name: "webhook-conf"
    hostPath: "/webhook/"
    mountPath: "/webhook/"
    readOnly: true
    pathType: DirectoryOrCreate
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
#APIEndpoint:
#  advertiseAddress: "192.168.224.22"
#  bindPort: 6443
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.15.10
networking:
#  advertiseAddress: "192.168.224.22"
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

This is what I'm trying to configure.

Choline answered 25/2, 2020 at 9:17 Comment(0)
C
7

To specify the --apiserver-advertise-address flag in the kubeadm config file use this in the init configuration:

localAPIEndpoint:
  advertiseAddress: 192.168.224.22
  bindPort: 6443

Initially when I was using this the address changed but then the worker nodes were not able to join the cluster due to a CRI socket misconfiguration.

Turns out using kubeadm config view doesn't print out the entire configuration that was used during cluster creation. The kind: InitConfiguration is skipped, due to which the misconfiguration occured.

Use kubeadm config print init-defaults to get the init block of the config file. Then it should work.

Final working config file:

apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.224.22
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: hostname1
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  extraArgs:
    authorization-mode: Node,RBAC
    authentication-token-webhook-config-file: /webhook/webhook-config.yaml
  extraVolumes:
  - name: "webhook-conf"
    hostPath: "/webhook/"
    mountPath: "/webhook/"
    readOnly: true
    pathType: DirectoryOrCreate
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.15.10
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}
Choline answered 25/2, 2020 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.