k8s cluster deployment 3: master node component deployment

Posted by TechXpert on Sun, 05 Apr 2020 01:34:59 +0200

All of the following are executed on the master

Get master node binary package

Download binary packages and deploy components

The binary package of the master node can be obtained from this website: kubernetes github

wget https://dl.k8s.io/v1.9.0/kubernetes-server-linux-amd64.tar.gz

Extract the Kube apiserver Kube Controller Manager kubectl Kube scheduler and put them on the master node.

mv kube-apiserver kube-controller-manager kube-scheduler /opt/kubernetes/bin/
chmod +x /opt/kubernetes/bin/{kube-apiserver,kube-controller-manager,kube-scheduler}

Kube API server configuration

Specify the ip address of the master and etcd

MASTER_ADDRESS="10.10.99.225"
ETCD_SERVERS="https://10.10.99.225:2379,https://10.10.99.228:2379,https://10.10.99.233:2379"

Generate Kube API server configuration file

cat <<EOF >/opt/kubernetes/cfg/kube-apiserver

KUBE_APISERVER_OPTS="--logtostderr=true \\
--v=4 \\
--etcd-servers=${ETCD_SERVERS} \\
--insecure-bind-address=127.0.0.1 \\
--bind-address=${MASTER_ADDRESS} \\
--insecure-port=8080 \\
--secure-port=6443 \\
--advertise-address=${MASTER_ADDRESS} \\
--allow-privileged=true \\
--service-cluster-ip-range=10.10.10.0/24 \\
--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota,NodeRestriction \
--authorization-mode=RBAC,Node \\
--kubelet-https=true \\
--enable-bootstrap-token-auth \\
--token-auth-file=/opt/kubernetes/cfg/token.csv \\
--service-node-port-range=30000-50000 \\
--tls-cert-file=/opt/kubernetes/ssl/server.pem  \\
--tls-private-key-file=/opt/kubernetes/ssl/server-key.pem \\
--client-ca-file=/opt/kubernetes/ssl/ca.pem \\
--service-account-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--etcd-cafile=/opt/kubernetes/ssl/ca.pem \\
--etcd-certfile=/opt/kubernetes/ssl/server.pem \\
--etcd-keyfile=/opt/kubernetes/ssl/server-key.pem"

EOF

Generating the Kube API server launcher

cat <<EOF >/usr/lib/systemd/system/kube-apiserver.service
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-apiserver
ExecStart=/opt/kubernetes/bin/kube-apiserver \$KUBE_APISERVER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

Copy the token file to the ssl directory under the k8s installation directory

cp /root/ssl/token.csv /opt/kubernetes/cfg/

Launch Kube apiserver

systemctl daemon-reload
systemctl start kube-apiserver.service
systemctl status kube-apiserver.service 
systemctl enable kube-apiserver.service

Kube controller manager configuration

Generate Kube controller manager configuration file

cat <<EOF >/opt/kubernetes/cfg/kube-controller-manager
KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \\
--v=4 \\
--master=127.0.0.1:8080 \\
--leader-elect=true \\
--address=127.0.0.1 \\
--service-cluster-ip-range=10.10.10.0/24 \\
--cluster-name=kubernetes \\
--cluster-signing-cert-file=/opt/kubernetes/ssl/ca.pem \\
--cluster-signing-key-file=/opt/kubernetes/ssl/ca-key.pem  \\
--service-account-private-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--root-ca-file=/opt/kubernetes/ssl/ca.pem"

EOF

Generate Kube controller manager startup file

cat <<EOF >/usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-controller-manager
ExecStart=/opt/kubernetes/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

Start Kube Controller Manager

systemctl daemon-reload
systemctl start kube-controller-manager.service
systemctl status kube-controller-manager.service 
systemctl enable kube-controller-manager.service

Kube scheduler configuration

Create a Kube scheduler profile

cat <<EOF >/opt/kubernetes/cfg/kube-scheduler
KUBE_SCHEDULER_OPTS="--logtostderr=true \\
--v=4 \\
--master=127.0.0.1:8080 \\
--leader-elect"
EOF

Create a Kube scheduler startup file

cat <<EOF >/usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-scheduler
ExecStart=/opt/kubernetes/bin/kube-scheduler \$KUBE_SCHEDULER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

Launch Kube scheduler

systemctl daemon-reload
systemctl start kube-scheduler.service
systemctl status kube-scheduler.service 
systemctl enable kube-scheduler.service

Check the status of each component of the master node

kubectl get cs

Topics: Kubernetes SSL github Linux