五、ubuntu16/Centos7上部署安装k8s1.9(二进制包)
5.1 主机节点规划
角色 | 主机名 | 主机ip | 组件 |
---|---|---|---|
etcd | etcd | 192.168.0.106 | etcd |
master | kube-master | 192.168.0.107 | kube-apiserver,kube-controller-manager,kube-scheduler |
node1 | kube-node1 | 192.168.0.108 | kubelet,kube-proxy,docker |
node2 | kube-node2 | 192.168.0.109 | kubelet,kube-proxy,docker |
node3 | kube-node3 | 192.168.0.110 | kubelet,kube-proxy,docker |
5.2 k8s各组件的安装顺序
- 获取kubernetes二进制包
- 运行master组件
- 运行node组件以及安装Docker
- 检查集群状态
- 测试运行Demo实例
5.2.0 初始化所有的节点信息
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
关闭selinux
setenforce 0
grep -E ‘^SELINUX=‘ /etc/sysconfig/selinux //如果是enforcing,则将其关闭
[[email protected] ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/sysconfig/selinux
[[email protected] ~]# grep -E ‘^SELINUX=‘ /etc/sysconfig/selinux
SELINUX=disabled
创建k8s二进制执行文件和配置文件的存放目录以及命令行程序的环境变量信息
mkdir -pv /opt/kubernetes/{bin,cfg} && echo "export PATH=$PATH:/opt/kubernetes/bin" >> /etc/profile && source /etc/profile
5.2.1 获取k8s二进制包
在kubernetes in github的仓库中找到CHANGELOG-*.md
,里面会找到各个版本的二进制文件,以及安装K8s平台组件的Shell安装脚本,==注意这些脚本在安装的时候要根据自己实际存放二进制的位置做出相应的调整==
下载的文件如下
-rw-r--r--. 1 root root 15628779 Aug 4 16:41 kubernetes-client-linux-1.9.1-amd64.tar.gz
-rw-r--r--. 1 root root 418747484 Aug 4 16:41 kubernetes-server-linux-1.9.1-amd64.tar.gz
-rw-r--r--. 1 root root 2877413 Aug 4 18:28 kubernetes.tar.gz
解压之后按照==主机节点规划==中的说明归档相应的二进制程序文件
tar xf kubernetes-client-linux-1.9.1-amd64.tar.gz
tar xf kubernetes-server-linux-1.9.1-amd64.tar.gz
tar xf kubernetes.tar.gz
解压之后,三个压缩包文件解压后都会存放在同一个叫做Kubernetes的目录中
==准备kube-master节点运行的文件==
cp /root/kubernetes/cluster/centos/master/scripts/{apiserver.sh,controller-manager.sh,scheduler.sh} /opt/kubernetes/
cp /root/kubernetes/server/bin/{kube-controller-manager,kube-scheduler,kube-apiserver,kubectl} /opt/kubernetes/bin/
==准备kube-node节点运行的文件==
cp /root/kubernetes/cluster/centos/node/scripts/{proxy.sh,kubelet.sh} /opt/kubernetes/
cp /root/kubernetes/server/bin/{kubelet,kube-proxy} /opt/kubernetes/bin
5.2.2 安装配置ETCD
因为是测试环境,我们暂且安装一个etcd单节点
yum install epel-release -y
yum install etcd
[[email protected] ~]# cat /etc/etcd/etcd.conf |awk ‘{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}‘
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://192.168.0.106:2379"
ETCD_NAME="k8setcd"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.106:2379"
systemctl start etcd
systemctl status etcd
systemctl enable etcd
journalctl -u etcd //查看日志
5.2.3 运行master组件
- 首先运行apiserver.sh
- 其次是scheduler.sh
- 再者是controller-manager.sh
==脚本中需要注意的地方==
- 脚本中的对应的MASTER_ADDRESS,ETCD_SERVERS,以及NODE_ADDRESS都有默认的值,如果我们在此修改成我们自己对应的信息ip,脚本运行不用添加参加,否则需要安装脚本中的顺序添加脚本参数
- 脚本中指定二进制以及组件的配置信息的存储位置,可以按情况修改
修改apiserver.sh脚本
[[email protected] kubernetes]# cat apiserver.sh |awk ‘{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}‘
MASTER_ADDRESS=${1:-"192.168.0.107"}
ETCD_SERVERS=${2:-"https://192.168.0.106:2379"}
SERVICE_CLUSTER_IP_RANGE=${3:-"10.10.10.0/24"}
ADMISSION_CONTROL=${4:-""}
cat <<EOF >/opt/kubernetes/cfg/kube-apiserver
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=4"
KUBE_ETCD_SERVERS="--etcd-servers=${ETCD_SERVERS}"
KUBE_API_ADDRESS="--insecure-bind-address=192.168.0.107"
KUBE_API_PORT="--insecure-port=8080"
NODE_PORT="--kubelet-port=10250"
KUBE_ADVERTISE_ADDR="--advertise-address=${MASTER_ADDRESS}"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=${SERVICE_CLUSTER_IP_RANGE}"
KUBE_ADMISSION_CONTROL="--admission-control=${ADMISSION_CONTROL}"
EOF
KUBE_APISERVER_OPTS=" \${KUBE_LOGTOSTDERR} \ \${KUBE_LOG_LEVEL} \ \${KUBE_ETCD_SERVERS} \ \${KUBE_ETCD_CAFILE} \ \${KUBE_ETCD_CERTFILE} \ \${KUBE_ETCD_KEYFILE} \ \${KUBE_API_ADDRESS} \ \${KUBE_API_PORT} \ \${NODE_PORT} \ \${KUBE_ADVERTISE_ADDR} \ \${KUBE_ALLOW_PRIV} \ \${KUBE_SERVICE_ADDRESSES} \ \${KUBE_ADMISSION_CONTROL} \ \${KUBE_API_CLIENT_CA_FILE} \ \${KUBE_API_TLS_CERT_FILE} \ \${KUBE_API_TLS_PRIVATE_KEY_FILE}"
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
systemctl daemon-reload
systemctl enable kube-apiserver
systemctl restart kube-apiserver
运行kube-master节点上组件的脚本
//因为我们修改过脚本,因此这些参数加不加都无所谓
/opt/kubernetes/apiserver.sh 192.168.0.107 http://192.168.0.106:2379
/opt/kubernetes/scheduler.sh 192.168.0.107
/opt/kubernetes/controller-manager.sh 192.168.0.107
检查进程
[[email protected] kubernetes]# ps -ef | grep kube | grep -v grep
root 2280 1 2 17:20 ? 00:04:32 /opt/kubernetes/bin/kube-apiserver --logtostderr=true --v=4 --etcd-servers=http://192.168.0.106:2379 --insecure-bind-address=192.168.0.107 --insecure-port=8080 --kubelet-port=10250 --advertise-address=192.168.0.107 --allow-privileged=false --service-cluster-ip-range=10.10.10.0/24 --admission-control=
root 2404 1 1 17:23 ? 00:01:53 /opt/kubernetes/bin/kube-scheduler --logtostderr=true --v=4 --master=192.168.0.107:8080 --leader-elect
root 2554 1 1 17:25 ? 00:03:16 /opt/kubernetes/bin/kube-controller-manager --logtostderr=true --v=4 --master=192.168.0.107:8080 --leader-elect
5.2.4 查看日志的方式
- k8s组件的日志信息默认输出到系统的日志中,centos系统在
/var/log/message
,ubuntu系统在/var/log/syslog
- 使用journalctl查看,比如查看apiserver的日志
[[email protected] ~]# journalctl -u kube-apiserver -- Logs begin at 六 2018-08-04 18:19:18 CST, end at 六 2018-08-04 20:06:56 CST. -- 8月 04 18:19:18 master kube-apiserver[2280]: I0804 18:19:18.706331 2280 get.go:238] Starting watch for /apis/extensions/v1beta1/da 8月 04 18:19:18 master kube-apiserver[2280]: I0804 18:19:18.718459 2280 wrap.go:42] GET /api/v1/namespaces/default: (2.497133ms) 2 8月 04 18:19:18 master kube-apiserver[2280]: I0804 18:19:18.722771 2280 wrap.go:42] GET /api/v1/namespaces/default/services/kubern 8月 04 18:19:18 master kube-apiserver[2280]: I0804 18:19:18.727262 2280 wrap.go:42] GET /api/v1/namespaces/default/endpoints/kuber 8月 04 18:19:19 master kube-apiserver[2280]: I0804 18:19:19.013099 2280 wrap.go:42] GET /api/v1/namespaces/kube-system/endpoints/k
5.2.5 运行kube-node组件
/opt/kubernetes/kubelet.sh
/opt/kubernetes/proxy.sh
[[email protected] kubernetes]# ps -ef | grep kube|grep -v grep
root 2821 1 2 18:41 ? 00:02:08 /opt/kubernetes/bin/kubelet --logtostderr=true --v=4 --address=192.168.0.108 --port=10250 --hostname-override=192.168.0.108 --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig --allow-privileged=false --cluster-dns=192.168.0.1 --cluster-domain=cluster.local
root 2955 1 0 18:43 ? 00:00:13 /opt/kubernetes/bin/kube-proxy --logtostderr=true --v=4 --hostname-override=192.168.0.108 --master=http://192.168.0.107:8080
5.2.6 检查k8s平台组件信息
[[email protected] ~]# kubectl get componentstatus
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health": "true"}
5.2.7 部署一个nginx
kubectl run nginx --image=nginx --replicas=3
六、学习场景
- 使用play with k8s
- 部署一个云原生的k8s实验环境
- 在Centos上部署k8s
- http://blog.51cto.com/bigboss/2153651
- https://zhangguanzhang.github.io/2018/08/03/Kubernetes_install_1.11.1/
- Ansible一键部署k8s
- kubernetes1.8部署方案:https://blog.qikqiak.com/post/manual-install-high-available-kubernetes-cluster/
- kubernetes1.10部署方案:https://zhangguanzhang.github.io/2018/05/05/Kubernetes_install/
- kubernetes1.11部署方案:https://zhangguanzhang.github.io/2018/08/03/Kubernetes_install_1.11.1/
原文地址:http://blog.51cto.com/bkmaster/2328317
时间: 2024-10-11 05:06:18