[!TIP] copy ected certificates to peer control nodes
# running in primary control plane node$foriin{2..3}; dosshmaster0${i} 'sudo mkdir -p ${etcdSSLPath}'for pkg inca-config.jsonca-key.pemca.pemclient-key.pemclient.pem; dorsync-avzrlpgoDP \--rsync-path='sudo rsync' \ ${etcdSSLPath}/${pkg} \master0${i}:${etcdSSLPath}/donedone# or running in peer control nodes one by one$forpkginca-config.jsonca-key.pemca.pemclient-key.pemclient.pem; dosudorsync-avzrlpgoDP \--rsync-path='sudo rsync' \root@${leadHost}:${etcdSSLPath}/${pkg} \ ${etcdSSLPath}/done
$sudobash-c'cat >/etc/systemd/system/etcd.service'<<EOF[Install]WantedBy=multi-user.target[Unit]Description=Etcd ServerDocumentation=https://github.com/Marslo/mytoolsConflicts=etcd.serviceConflicts=etcd2.service[Service]Type=notifyWorkingDirectory=/var/lib/etcd/Restart=alwaysRestartSec=5sEnvironmentFile=-/etc/etcd/etcd.confExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/local/bin/etcd"Restart=on-failureRestartSec=5LimitNOFILE=65536[Install]WantedBy=multi-user.targetEOF$sudobash-c'cat > /etc/etcd/etcd.conf'<<EOFETCD_NAME=${peerName}ETCD_DATA_DIR="/var/lib/etcd/default.etcd"#ETCD_WAL_DIR=""#ETCD_SNAPSHOT_COUNT="10000"#ETCD_HEARTBEAT_INTERVAL="100"#ETCD_ELECTION_TIMEOUT="1000"ETCD_LISTEN_PEER_URLS="https://0.0.0.0:2380"ETCD_LISTEN_CLIENT_URLS="https://0.0.0.0:2379"#ETCD_MAX_SNAPSHOTS="5"#ETCD_MAX_WALS="5"#ETCD_CORS=""##[cluster]ETCD_INITIAL_ADVERTISE_PEER_URLS="https://${ipAddr}:2380"# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."ETCD_INITIAL_CLUSTER="${etcdInitialCluster}"ETCD_INITIAL_CLUSTER_STATE="new"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"ETCD_ADVERTISE_CLIENT_URLS="https://${ipAddr}:2379"#ETCD_DISCOVERY=""#ETCD_DISCOVERY_SRV=""#ETCD_DISCOVERY_FALLBACK="proxy"#ETCD_DISCOVERY_PROXY=""#ETCD_STRICT_RECONFIG_CHECK="false"#ETCD_AUTO_COMPACTION_RETENTION="0"##[proxy]#ETCD_PROXY="off"#ETCD_PROXY_FAILURE_WAIT="5000"#ETCD_PROXY_REFRESH_INTERVAL="30000"#ETCD_PROXY_DIAL_TIMEOUT="1000"#ETCD_PROXY_WRITE_TIMEOUT="5000"#ETCD_PROXY_READ_TIMEOUT="0"##[security]ETCD_CERT_FILE="${etcdSSLPath}/server.pem"ETCD_KEY_FILE="${etcdSSLPath}/server-key.pem"ETCD_CLIENT_CERT_AUTH="true"ETCD_TRUSTED_CA_FILE="${etcdSSLPath}/ca.pem"ETCD_AUTO_TLS="true"ETCD_PEER_CERT_FILE="${etcdSSLPath}/peer.pem"ETCD_PEER_KEY_FILE="${etcdSSLPath}/peer-key.pem"#ETCD_PEER_CLIENT_CERT_AUTH="false"ETCD_PEER_TRUSTED_CA_FILE="${etcdSSLPath}/ca.pem"ETCD_PEER_AUTO_TLS="true"##[logging]#ETCD_DEBUG="false"# examples for -log-package-levels etcdserver=WARNING,security=DEBUG#ETCD_LOG_PACKAGE_LEVELS=""#[profiling]#ETCD_ENABLE_PPROF="false"#ETCD_METRICS="basic"EOF$sudosystemctldaemon-reload$sudosystemctlenable--nowetcd$sudosystemctlstartetcd.service
HAProxy
[!TIP] for HA-Proxy version 2.0.6
$sudobash-c'cat > /etc/haproxy/haproxy.cfg'<<EOF#---------------------------------------------------------------------# Example configuration for a possible web application. See the# full configuration options online.## http://haproxy.1wt.eu/download/2.0/doc/configuration.txt##---------------------------------------------------------------------#---------------------------------------------------------------------# Global settings#---------------------------------------------------------------------global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats#---------------------------------------------------------------------# common defaults that all the 'listen' and 'backend' sections will# use if not designated in their block#---------------------------------------------------------------------defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000#---------------------------------------------------------------------# kubernetes apiserver frontend which proxys to the backends#---------------------------------------------------------------------frontend kubernetes-apiserver mode tcp bind *:16443 option tcplog default_backend kubernetes-apiserver#---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------backend kubernetes-apiserver mode tcp balance roundrobin option tcplog option tcp-check server ${controller01Name} ${controller01IP}:6443 check server ${controller02Name} ${controller02IP}:6443 check server ${controller03Name} ${controller03IP}:6443 check#---------------------------------------------------------------------# collection haproxy statistics message#---------------------------------------------------------------------listen stats# bind *:1080 bind :8000 stats auth <admin>:<password> maxconn 50 stats refresh 10s stats realm HAProxy\ Statistics stats uri /healthy$ sudo systemctl enable haproxy.service$ sudo systemctl start haproxy.service$ sudo ss -lnt | grep -E "16443|8080"
# Update HOST0, HOST1 and HOST2 with the IPs of your hostsexport HOST0=10.0.0.6export HOST1=10.0.0.7export HOST2=10.0.0.8# update NAME0, NAME1 and NAME2 with the hostnames of your hostsexport NAME0="infra0"export NAME1="infra1"export NAME2="infra2"# create temp directories to store files that will end up on other hosts.mkdir-p/tmp/${HOST0}//tmp/${HOST1}//tmp/${HOST2}/HOSTS=(${HOST0} ${HOST1} ${HOST2})NAMES=(${NAME0} ${NAME1} ${NAME2})for i in"${!HOSTS[@]}"; doHOST=${HOSTS[$i]}NAME=${NAMES[$i]}cat<<EOF>/tmp/${HOST}/kubeadmcfg.yaml---apiVersion: "kubeadm.k8s.io/v1beta3"kind: InitConfigurationnodeRegistration: name: ${NAME}localAPIEndpoint: advertiseAddress: ${HOST}---apiVersion: "kubeadm.k8s.io/v1beta3"kind: ClusterConfigurationetcd: local: serverCertSANs: - "${HOST}" peerCertSANs: - "${HOST}" extraArgs: initial-cluster: ${NAMES[0]}=https://${HOSTS[0]}:2380,${NAMES[1]}=https://${HOSTS[1]}:2380,${NAMES[2]}=https://${HOSTS[2]}:2380
initial-cluster-state: new name: ${NAME} listen-peer-urls: https://${HOST}:2380 listen-client-urls: https://${HOST}:2379 advertise-client-urls: https://${HOST}:2379 initial-advertise-peer-urls: https://${HOST}:2380EOFdone
Generate the certificate authority
[!TIP] to generate:
/etc/kubernetes/pki/etcd/ca.crt
/etc/kubernetes/pki/etcd/ca.key
$kubeadminitphasecertsetcd-ca
Create certificates for each member
kubeadminitphasecertsetcd-server--config=/tmp/${HOST2}/kubeadmcfg.yamlkubeadminitphasecertsetcd-peer--config=/tmp/${HOST2}/kubeadmcfg.yamlkubeadminitphasecertsetcd-healthcheck-client--config=/tmp/${HOST2}/kubeadmcfg.yamlkubeadminitphasecertsapiserver-etcd-client--config=/tmp/${HOST2}/kubeadmcfg.yamlcp-R/etc/kubernetes/pki/tmp/${HOST2}/# cleanup non-reusable certificatesfind/etc/kubernetes/pki-not-nameca.crt-not-nameca.key-typef-deletekubeadminitphasecertsetcd-server--config=/tmp/${HOST1}/kubeadmcfg.yamlkubeadminitphasecertsetcd-peer--config=/tmp/${HOST1}/kubeadmcfg.yamlkubeadminitphasecertsetcd-healthcheck-client--config=/tmp/${HOST1}/kubeadmcfg.yamlkubeadminitphasecertsapiserver-etcd-client--config=/tmp/${HOST1}/kubeadmcfg.yamlcp-R/etc/kubernetes/pki/tmp/${HOST1}/find/etc/kubernetes/pki-not-nameca.crt-not-nameca.key-typef-deletekubeadminitphasecertsetcd-server--config=/tmp/${HOST0}/kubeadmcfg.yamlkubeadminitphasecertsetcd-peer--config=/tmp/${HOST0}/kubeadmcfg.yamlkubeadminitphasecertsetcd-healthcheck-client--config=/tmp/${HOST0}/kubeadmcfg.yamlkubeadminitphasecertsapiserver-etcd-client--config=/tmp/${HOST0}/kubeadmcfg.yaml# No need to move the certs because they are for HOST0# clean up certs that should not be copied off this hostfind/tmp/${HOST2} -nameca.key-typef-deletefind/tmp/${HOST1} -nameca.key-typef-delete
[!TIP] kubeadm init also exposes a flag called --skip-phases that can be used to skip certain phases. The flag accepts a list of phase names and the names can be taken from the above ordered list.
$sudokubeadminitphasecontrol-planeall--config=configfile.yaml$sudokubeadminitphaseetcdlocal--config=configfile.yaml# you can now modify the control plane and etcd manifest files$sudokubeadminit--skip-phases=control-plane,etcd--config=configfile.yaml