Kubernetes安装系列之Master-controller-manager安装

这篇文章整理以下Master节点的controller-manager的安装与设定方法,本文以脚本的方式进行固化,内容仍然放在github的easypack上。

整体操作

  • https://blog.csdn.net/liumiaocn/article/details/88413428

controller-manager的设定文件

[root@host131 shell]# cat /etc/k8s/controller-manager.conf 
KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \
--v=4 \
--log-dir=/var/log/kubernetes \
--master=127.0.0.1:8080 \
--leader-elect=true \
--address=127.0.0.1 \
--service-cluster-ip-range=172.200.0.0/16 \
--cluster-name=kubernetes \
--cluster-signing-cert-file=/etc/ssl/ca/ca.pem \
--cluster-signing-key-file=/etc/ssl/ca/ca-key.pem  \
--root-ca-file=/etc/ssl/ca/ca.pem \
--service-account-private-key-file=/etc/ssl/ca/ca-key.pem"
[root@host131 shell]# 

Systemd服务配置文件

[root@host131 shell]# cat /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/etc/k8s/controller-manager.conf
ExecStart=/usr/local/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@host131 shell]#

脚本示例

[root@host131 shell]# cat step5-install-controller-manager.sh 
#!/bin/sh

. ./install.cfg

echo -e "\n##  kube-controller-manager service"
systemctl stop kube-controller-manager 2>/dev/null

mkdir -p ${ENV_KUBE_DIR_BIN} ${ENV_KUBE_DIR_ETC} ${ENV_KUBE_OPT_LOG_DIR}
chmod 755 ${ENV_HOME_K8S}/*
cp -p ${ENV_HOME_K8S}/kube-controller-manager ${ENV_KUBE_DIR_BIN}
if [ $? -ne 0 ]; then
  echo "please check kube-controller-manager binary files existed in ${ENV_HOME_K8S}/ or not"
  exit 
fi

# create kube-controller-manager configuration file
cat >${ENV_KUBE_DIR_ETC}/${ENV_KUBE_CM_ETC} <<EOF
KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=${ENV_KUBE_OPT_LOGTOSTDERR} \
--v=${ENV_KUBE_OPT_LOG_LEVEL} \
--log-dir=${ENV_KUBE_OPT_LOG_DIR} \
--master=${ENV_KUBE_MASTER_ADDR} \
--leader-elect=${ENV_KUBE_OPT_LEADER_ELECT} \
--address=${ENV_KUBE_OPT_LOCALHOST} \
--service-cluster-ip-range=${ENV_KUBE_OPT_CLUSTER_IP_RANGE} \
--cluster-name=${ENV_KUBE_OPT_CLUSTER_NAME} \
--cluster-signing-cert-file=${ENV_SSL_CA_DIR}/${ENV_SSL_FILE_CA_PEM} \
--cluster-signing-key-file=${ENV_SSL_CA_DIR}/${ENV_SSL_FILE_CA_KEY}  \
--root-ca-file=${ENV_SSL_CA_DIR}/${ENV_SSL_FILE_CA_PEM} \
--service-account-private-key-file=${ENV_SSL_CA_DIR}/${ENV_SSL_FILE_CA_KEY}"
EOF

# Create the kube-controller-manager service.
cat >${ENV_KUBE_CM_SERVICE} <<EOF
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-${ENV_KUBE_DIR_ETC}/${ENV_KUBE_CM_ETC}
ExecStart=${ENV_KUBE_DIR_BIN}/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

echo -e "\n##  daemon reload service "
systemctl daemon-reload
echo -e "\n##  start kube-controller-manager service "
systemctl start kube-controller-manager
echo -e "\n##  enable kube-controller-manager service " 
systemctl enable kube-controller-manager
echo -e "\n##  check  kube-controller-manager status"
systemctl status kube-controller-manager

# sleep 2 seconds for checking
sleep 2

echo -e "\n##  get cs"
kubectl get cs
[root@host131 shell]# 

执行示例

[root@host131 shell]# sh step5-install-controller-manager.sh 

##  kube-controller-manager service

##  daemon reload service 

##  start kube-controller-manager service 

##  enable kube-controller-manager service 
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to /usr/lib/systemd/system/kube-controller-manager.service.

##  check  kube-controller-manager status
● kube-controller-manager.service - Kubernetes Controller Manager
   Loaded: loaded (/usr/lib/systemd/system/kube-controller-manager.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-03-23 17:09:32 CST; 298ms ago
     Docs: https://github.com/kubernetes/kubernetes
 Main PID: 10838 (kube-controller)
   CGroup: /system.slice/kube-controller-manager.service
           └─10838 /usr/local/bin/kube-controller-manager --logtostderr=true --v=4 --log-dir=/var/log/kubernetes --master=127.0.0.1:8080 --lea...

Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263505   10838 flags.go:33] FLAG: --horizontal-pod-autoscaler-ini...="30s"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263512   10838 flags.go:33] FLAG: --horizontal-pod-autoscaler-syn...="15s"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263518   10838 flags.go:33] FLAG: --horizontal-pod-autoscaler-tol...="0.1"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263528   10838 flags.go:33] FLAG: --horizontal-pod-autoscaler-ups..."3m0s"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263535   10838 flags.go:33] FLAG: --horizontal-pod-autoscaler-use..."true"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263541   10838 flags.go:33] FLAG: --http2-max-streams-per-connection="0"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263549   10838 flags.go:33] FLAG: --kube-api-burst="30"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263556   10838 flags.go:33] FLAG: --kube-api-content-type="applic...tobuf"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263563   10838 flags.go:33] FLAG: --kube-api-qps="20"
Mar 23 17:09:32 host131 kube-controller-manager[10838]: I0323 17:09:32.263570   10838 flags.go:33] FLAG: --kubeconfig=""
Hint: Some lines were ellipsized, use -l to show in full.

##  get cs
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok                  
controller-manager   Healthy   ok                  
etcd-0               Healthy   {"health":"true"}   
[root@host131 shell]# 

安装之后可以通过kubectl get cs确认到controller-manager的Status也变成了Healthy状态,这样Master节点所需的主要部分就完成了。

你可能感兴趣的:(#,深入浅出kubernetes)