kubernetes节点安装配置

#环境安装,要与控制节点一致
Centos 7 Linux release 7.3.1611
网络: 互通
配置主机名
设置各个服务器的主机名hosts
#查找kubernetes支持的docker版本
Kubernetes v1.7.5 == Docker 1.12.6
#然后到https://yum.dockerproject.org/repo/main/centos/7/Packages/下载安装
############################################################################################################################
#DOCKER 安装
#安装后启动并设置为开机自启
rpm –ivh https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.12.6-1.el7.centos.x86_64.rpm
sudo systemctl start docker
sudo systemctl enable docker

############################################
#安装Kubernetes
#下载地址: https://github.com/kubernetes/kubernetes/releases/tag/v1.7.5
tar zxf kubernetes-server-linux-amd64.tar.gz
sh cluster/get-kube-binaries.sh
cd server
tar xf kubernetes-server-linux-amd64.tar.gz
cd server/bin
#准备证书
mkdir /etc/kubernetes/crt
cd /etc/kubernetes/crt
#将master的ca.crt和ca.key复制到节点上192.168.1.2替换为本机IP
openssl genrsa -out kubelet_client.key 2048
openssl req -new -key kubelet_client.key -subj "/CN=192.168.1.2" -out kubelet_client.csr
openssl x509 -req -in kubelet_client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out kubelet_client.crt -days 5000
cd -
#创建kubeconfig文件
cat << EOF > /etc/kubernetes/kubeconfig
apiVersion: v1
kind: Config
users:
- name: kubelet
  user:
    client-certificate: /etc/kubernetes/crt/kubelet_client.crt
    client-key: /etc/kubernetes/crt/kubelet_client.key
clusters:
- name: local
  cluster:
    certificate-authority: /etc/kubernetes/crt/ca.crt
contexts:
- context:
    cluster: local
    user: kubelet
  name: my-context
current-context: my-context
EOF

################################
#安装kubelet
cp kubelet /usr/bin/
cat << EOF > /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet $KUBELET_ARGS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
#192.168.1.1替换为控制节点IP,minion-2替换为本机主机名,169.169.0.10替换为要设置的kubeDNS IP
cat << EOF >/etc/kubernetes/kubelet
KUBELET_ARGS="--api-servers=https://192.168.1.1:8080 --hostname-override=minion-2 --logtostderr=false \
--log-dir=/var/log/kubernetes --v=2 \
--kubeconfig=/etc/kubernetes/kubeconfig \
--root-dir=/data/kubelet \
--cluster-dns=169.169.0.10"
EOF

#安装kube-proxy
cp ../kube-proxy /usr/bin
cat << EOF >/usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
Requires=network.service

[Service]
EnvironmentFile=/etc/kubernetes/proxy
ExecStart=/usr/bin/kube-proxy $KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF
#192.168.1.1替换为控制节点IP,169.169.0.0/16替换为之前设置的集群IP段
cat << EOF >/etc/kubernetes/proxy
KUBE_PROXY_ARGS="--master=https://192.168.1.1:8080 \
--logtostderr=false --log-dir=/var/log/kubernetes --v=2 \
--kubeconfig=/etc/kubernetes/kubeconfig \
--cluster-cidr=169.169.0.0/16"
EOF
#启动
systemctl daemon-reload
for i in kubelet.service kube-proxy.service
do
systemctl enable $i
systemctl restart $i
systemctl status $i
done


posted @ 2018-03-16 13:57  IT菜鸟园  阅读(161)  评论(0编辑  收藏  举报