Kubelet determines the ips peresent on the node and since we have both ipv4 and ipv6 ips, we expect it to find the ips but it acts in an underministic way, sometimes finding the ip and sometimes no. We will explicitly provide the ipv4 and ipv6 ips to the each cluster vm using the kubelet extra args API present in the kubeadm config file. Also the API version of kubeadm is upgraded from v1beta3 to v1beta4. Join scripts for worker and control-plane nodes are also merged and with the help of a flag, the script is reused.
58 lines
1.3 KiB
Ruby
Executable File
58 lines
1.3 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "json"
|
|
require "yaml"
|
|
require_relative "../../common/lib/util"
|
|
|
|
params = JSON.parse($stdin.read)
|
|
|
|
begin
|
|
is_control_plane = params.fetch("is_control_plane")
|
|
endpoint = params.fetch("endpoint")
|
|
join_token = params.fetch("join_token")
|
|
discovery_token_ca_cert_hash = params.fetch("discovery_token_ca_cert_hash")
|
|
node_name = params.fetch("node_name")
|
|
node_ipv4 = params.fetch("node_ipv4")
|
|
node_ipv6 = params.fetch("node_ipv6")
|
|
if is_control_plane
|
|
certificate_key = params.fetch("certificate_key")
|
|
end
|
|
rescue KeyError => e
|
|
puts "Needed #{e.key} in parameters"
|
|
exit 1
|
|
end
|
|
|
|
config = {
|
|
"apiVersion" => "kubeadm.k8s.io/v1beta4",
|
|
"kind" => "JoinConfiguration",
|
|
"discovery" => {
|
|
"bootstrapToken" => {
|
|
"token" => join_token,
|
|
"apiServerEndpoint" => endpoint,
|
|
"caCertHashes" => [discovery_token_ca_cert_hash]
|
|
}
|
|
},
|
|
"nodeRegistration" => {
|
|
"name" => node_name,
|
|
"kubeletExtraArgs" => [
|
|
{
|
|
"name" => "node-ip",
|
|
"value" => "#{node_ipv4},#{node_ipv6}"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
if is_control_plane
|
|
config["controlPlane"] = {
|
|
"certificateKey" => certificate_key
|
|
}
|
|
end
|
|
|
|
config_path = "/tmp/join-config.yaml"
|
|
safe_write_to_file(config_path, config.to_yaml)
|
|
r("kubeadm join --config #{config_path}")
|
|
|
|
r("sudo /home/ubi/kubernetes/bin/setup-cni")
|