mirror of
https://github.com/rancher/rke.git
synced 2025-08-17 22:37:01 +00:00
renamed ControlPlaneIP
This commit is contained in:
parent
1bb4ab98c3
commit
dbc7dfaafe
@ -5,12 +5,12 @@ hosts:
|
|||||||
user: ubuntu
|
user: ubuntu
|
||||||
role: [controlplane, etcd]
|
role: [controlplane, etcd]
|
||||||
docker_socket: /var/run/docker.sock
|
docker_socket: /var/run/docker.sock
|
||||||
control_plane_ip: 10.1.1.1
|
advertise_address: 10.1.1.1
|
||||||
- hostname: server2
|
- hostname: server2
|
||||||
ip: 2.2.2.2
|
ip: 2.2.2.2
|
||||||
user: ubuntu
|
user: ubuntu
|
||||||
role: [worker]
|
role: [worker]
|
||||||
control_plane_ip: 10.2.2.2
|
advertise_address: 10.2.2.2
|
||||||
|
|
||||||
services:
|
services:
|
||||||
etcd:
|
etcd:
|
||||||
|
@ -123,10 +123,10 @@ func parseClusterFile(clusterFile string) (*services.Container, []hosts.Host, er
|
|||||||
} else if len(host.Role) == 0 {
|
} else if len(host.Role) == 0 {
|
||||||
return nil, nil, fmt.Errorf("Role for host (%d) is not provided", i+1)
|
return nil, nil, fmt.Errorf("Role for host (%d) is not provided", i+1)
|
||||||
|
|
||||||
} else if host.ControlPlaneIP == "" {
|
} else if host.AdvertiseAddress == "" {
|
||||||
// if control_plane_ip is not set,
|
// if control_plane_ip is not set,
|
||||||
// default to the main IP
|
// default to the main IP
|
||||||
host.ControlPlaneIP = host.IP
|
k8shosts.Hosts[i].AdvertiseAddress = host.IP
|
||||||
}
|
}
|
||||||
for _, role := range host.Role {
|
for _, role := range host.Role {
|
||||||
if role != services.ETCDRole && role != services.ControlRole && role != services.WorkerRole {
|
if role != services.ETCDRole && role != services.ControlRole && role != services.WorkerRole {
|
||||||
|
@ -10,13 +10,13 @@ type Hosts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Host struct {
|
type Host struct {
|
||||||
IP string `yaml:"ip"`
|
IP string `yaml:"ip"`
|
||||||
ControlPlaneIP string `yaml:"control_plane_ip"`
|
AdvertiseAddress string `yaml:"advertise_address"`
|
||||||
Role []string `yaml:"role"`
|
Role []string `yaml:"role"`
|
||||||
Hostname string `yaml:"hostname"`
|
Hostname string `yaml:"hostname"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
DockerSocket string `yaml:"docker_socket"`
|
DockerSocket string `yaml:"docker_socket"`
|
||||||
DClient *client.Client
|
DClient *client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func DivideHosts(hosts []Host) ([]Host, []Host, []Host) {
|
func DivideHosts(hosts []Host) ([]Host, []Host, []Host) {
|
||||||
|
12
pki/pki.go
12
pki/pki.go
@ -79,7 +79,7 @@ func generateCerts(cpHosts []hosts.Host, clusterDomain string, KubernetesService
|
|||||||
certs[KubeControllerName] = CertificatePKI{
|
certs[KubeControllerName] = CertificatePKI{
|
||||||
certificate: kubeControllerCrt,
|
certificate: kubeControllerCrt,
|
||||||
key: kubeControllerKey,
|
key: kubeControllerKey,
|
||||||
config: getKubeConfigX509("https://"+cpHosts[0].ControlPlaneIP+":6443", KubeControllerName, CACertPath, KubeControllerCertPath, KubeControllerKeyPath),
|
config: getKubeConfigX509("https://"+cpHosts[0].AdvertiseAddress+":6443", KubeControllerName, CACertPath, KubeControllerCertPath, KubeControllerKeyPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate Kube scheduler certificate and key
|
// generate Kube scheduler certificate and key
|
||||||
@ -92,7 +92,7 @@ func generateCerts(cpHosts []hosts.Host, clusterDomain string, KubernetesService
|
|||||||
certs[KubeSchedulerName] = CertificatePKI{
|
certs[KubeSchedulerName] = CertificatePKI{
|
||||||
certificate: kubeSchedulerCrt,
|
certificate: kubeSchedulerCrt,
|
||||||
key: kubeSchedulerKey,
|
key: kubeSchedulerKey,
|
||||||
config: getKubeConfigX509("https://"+cpHosts[0].ControlPlaneIP+":6443", KubeSchedulerName, CACertPath, KubeSchedulerCertPath, KubeSchedulerKeyPath),
|
config: getKubeConfigX509("https://"+cpHosts[0].AdvertiseAddress+":6443", KubeSchedulerName, CACertPath, KubeSchedulerCertPath, KubeSchedulerKeyPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate Kube Proxy certificate and key
|
// generate Kube Proxy certificate and key
|
||||||
@ -105,7 +105,7 @@ func generateCerts(cpHosts []hosts.Host, clusterDomain string, KubernetesService
|
|||||||
certs[KubeProxyName] = CertificatePKI{
|
certs[KubeProxyName] = CertificatePKI{
|
||||||
certificate: kubeProxyCrt,
|
certificate: kubeProxyCrt,
|
||||||
key: kubeProxyKey,
|
key: kubeProxyKey,
|
||||||
config: getKubeConfigX509("https://"+cpHosts[0].ControlPlaneIP+":6443", KubeProxyName, CACertPath, KubeProxyCertPath, KubeProxyKeyPath),
|
config: getKubeConfigX509("https://"+cpHosts[0].AdvertiseAddress+":6443", KubeProxyName, CACertPath, KubeProxyCertPath, KubeProxyKeyPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate Kubelet certificate and key
|
// generate Kubelet certificate and key
|
||||||
@ -118,7 +118,7 @@ func generateCerts(cpHosts []hosts.Host, clusterDomain string, KubernetesService
|
|||||||
certs[KubeNodeName] = CertificatePKI{
|
certs[KubeNodeName] = CertificatePKI{
|
||||||
certificate: nodeCrt,
|
certificate: nodeCrt,
|
||||||
key: nodeKey,
|
key: nodeKey,
|
||||||
config: getKubeConfigX509("https://"+cpHosts[0].ControlPlaneIP+":6443", KubeNodeName, CACertPath, KubeNodeCertPath, KubeNodeKeyPath),
|
config: getKubeConfigX509("https://"+cpHosts[0].AdvertiseAddress+":6443", KubeNodeName, CACertPath, KubeNodeCertPath, KubeNodeKeyPath),
|
||||||
}
|
}
|
||||||
return certs, nil
|
return certs, nil
|
||||||
}
|
}
|
||||||
@ -199,8 +199,8 @@ func getAltNames(cpHosts []hosts.Host, clusterDomain string, KubernetesServiceIP
|
|||||||
dnsNames := []string{}
|
dnsNames := []string{}
|
||||||
for _, host := range cpHosts {
|
for _, host := range cpHosts {
|
||||||
ips = append(ips, net.ParseIP(host.IP))
|
ips = append(ips, net.ParseIP(host.IP))
|
||||||
if host.IP != host.ControlPlaneIP {
|
if host.IP != host.AdvertiseAddress {
|
||||||
ips = append(ips, net.ParseIP(host.ControlPlaneIP))
|
ips = append(ips, net.ParseIP(host.AdvertiseAddress))
|
||||||
}
|
}
|
||||||
dnsNames = append(dnsNames, host.Hostname)
|
dnsNames = append(dnsNames, host.Hostname)
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,12 @@ func buildEtcdConfig(host hosts.Host, etcdService Etcd) (*container.Config, *con
|
|||||||
Cmd: []string{"/usr/local/bin/etcd",
|
Cmd: []string{"/usr/local/bin/etcd",
|
||||||
"--name=etcd-" + host.Hostname,
|
"--name=etcd-" + host.Hostname,
|
||||||
"--data-dir=/etcd-data",
|
"--data-dir=/etcd-data",
|
||||||
"--advertise-client-urls=http://" + host.ControlPlaneIP + ":2379,http://" + host.ControlPlaneIP + ":4001",
|
"--advertise-client-urls=http://" + host.AdvertiseAddress + ":2379,http://" + host.AdvertiseAddress + ":4001",
|
||||||
"--listen-client-urls=http://0.0.0.0:2379",
|
"--listen-client-urls=http://0.0.0.0:2379",
|
||||||
"--initial-advertise-peer-urls=http://" + host.ControlPlaneIP + ":2380",
|
"--initial-advertise-peer-urls=http://" + host.AdvertiseAddress + ":2380",
|
||||||
"--listen-peer-urls=http://0.0.0.0:2380",
|
"--listen-peer-urls=http://0.0.0.0:2380",
|
||||||
"--initial-cluster-token=etcd-cluster-1",
|
"--initial-cluster-token=etcd-cluster-1",
|
||||||
"--initial-cluster=etcd-" + host.Hostname + "=http://" + host.ControlPlaneIP + ":2380"},
|
"--initial-cluster=etcd-" + host.Hostname + "=http://" + host.AdvertiseAddress + ":2380"},
|
||||||
}
|
}
|
||||||
hostCfg := &container.HostConfig{
|
hostCfg := &container.HostConfig{
|
||||||
RestartPolicy: container.RestartPolicy{Name: "always"},
|
RestartPolicy: container.RestartPolicy{Name: "always"},
|
||||||
@ -64,7 +64,7 @@ func buildEtcdConfig(host hosts.Host, etcdService Etcd) (*container.Config, *con
|
|||||||
func getEtcdConnString(hosts []hosts.Host) string {
|
func getEtcdConnString(hosts []hosts.Host) string {
|
||||||
connString := ""
|
connString := ""
|
||||||
for i, host := range hosts {
|
for i, host := range hosts {
|
||||||
connString += "http://" + host.ControlPlaneIP + ":2379"
|
connString += "http://" + host.AdvertiseAddress + ":2379"
|
||||||
if i < (len(hosts) - 1) {
|
if i < (len(hosts) - 1) {
|
||||||
connString += ","
|
connString += ","
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func buildKubeAPIConfig(host hosts.Host, kubeAPIService KubeAPI, etcdConnString
|
|||||||
"--runtime-config=authentication.k8s.io/v1beta1=true",
|
"--runtime-config=authentication.k8s.io/v1beta1=true",
|
||||||
"--storage-backend=etcd3",
|
"--storage-backend=etcd3",
|
||||||
"--etcd-servers=" + etcdConnString,
|
"--etcd-servers=" + etcdConnString,
|
||||||
"--advertise-address=" + host.ControlPlaneIP,
|
"--advertise-address=" + host.AdvertiseAddress,
|
||||||
"--client-ca-file=" + pki.CACertPath,
|
"--client-ca-file=" + pki.CACertPath,
|
||||||
"--tls-cert-file=" + pki.KubeAPICertPath,
|
"--tls-cert-file=" + pki.KubeAPICertPath,
|
||||||
"--tls-private-key-file=" + pki.KubeAPIKeyPath,
|
"--tls-private-key-file=" + pki.KubeAPIKeyPath,
|
||||||
|
Loading…
Reference in New Issue
Block a user