CentOS 7 安装Kubernetes(1)--手动部署节点
手工安装Kubernetes
yum用起来很方便,但是为了更深入了解k8s的组成, 我还是选择了手工安装的方式进行kubernetes的安装和配置,这里分享一下。
1、安装etcd
从Github上找到最新发布的etcd,使用浏览器或者命令行下载
首先进入创建好的用户目录 /home/eos-master
(eos-master是我的用户名)
wget https://github.com/coreos/etcd/releases/download/v3.2.0/etcd-v3.2.0-linux-amd64.tar.gz
解压下载的文件
tar -xzf etcd-v3.2.0-linux-amd64.tar.gz
文件名太长,改一个文件名
mv etcd-v3.2.0-linux-amd64 etcd-3.2.0
创建软链接
ln -s /home/eos-master/etcd/etcd-3.2.0/* /usr/bin/
测试一下
etcd -version
创建系统服务
创建文件 /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/eos-master/etcd/
EnvironmentFile=/home/eos-master/etcd/etcd.conf
ExecStart=/usr/bin/etcd $ETCD_ARGS
[Install]
WantedBy=multi-user.target
vi /home/eos-master/etcd/etcd.conf
ETCD_ARGS=”–listen-client-urls=http://192.168.199.161:2379,http://127.0.0.1:2379 –advertise-client-urls=http://192.168.199.161:2379,http://127.0.0.1:2379”
这里把ip地址加入,不然不能远程链接。
启动服务
systemctl daemon-reload
systemctl start etcd.service
systemctl enable etcd.service
用客户端链接一下试试
etcdctl cluster-health
正常返回:
member 8e9e05c52164694d is healthy: got healthy result from http://localhost:2379
cluster is healthy
2、安装kubernetes master主节点
依然去github中找到kubernetes 的release版,我下载的是1.6.6,写这篇文章的时候1.7和1.8都有了,不过是pre-relase版的,我选择了stable
之前看了一些资料,以为kube-apiserver 会包含在下载的安装包server目录中,下载下来一看傻眼了,什么都没有。找了半天发现里面有个README文件,提示说需要运行cluster/get-kube-binaries.sh 下载客户端和服务器端的文件。这里真是个小经验,像我们用windows用多了的人readme什么的都是直接忽略的,看来linux里的readme真的会有一些有用的东西。
bush cluster/get-kube-binaries.sh
下载完之后提醒问我
Extracting /home/eos-master/kubernetes/client/kubernetes-client-linux-amd64.tar.gz into /home/eos-master/kubernetes/platforms/linux/amd64
Add ‘/home/eos-master/kubernetes/client/bin’ to your PATH to use newly-installed binaries.
提示里说的是client/kubernetes-client-linux-amd64.tar.gz 其实server/kubernetes-server-linux-amd64.tar.gz 才是服务器端,继续解压
tar -xzvf kubernetes-server-linux-amd64.tar.gz
还是和之前一样做个软连接,有时候不知道自己在目录的什么位置了可以使用pwd命令查询一下当前所在目录。linux界真的能瞎起名字,pwd怎么看是密码的意思….还有什么yum 竟然是yellow dog,跟dog有什么关系….
ln -s /home/eos-master/kubernetes/server/kubernetes/server/bin/* /usr/bin/
创建服务
创建文件 /usr/lib/systemd/system/kube-apiserver.servicekube-apiserver
[Unit]
Description=Kubernetes API Server
After=etcd.service
Wants=etcd.service
[Service]
Type=notify
EnvironmentFile=/home/eos-master/kubernetes/apiserver
ExecStart=/usr/bin/kube-apiserver $KUBE_API_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
然后创建配置文件
vi /home/eos-master/kubernetes/apiserver
文件内容是:
KUBE_API_ARGS=”–etcd_servers=http://127.0.0.1:2379 –insecure-bind-address=0.0.0.0 –insecure-port=8080 –service-cluster-ip-range=169.169.0.0/16 –service-node-port-range=1-65535 –admission_control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota –logtostderr=false –log-dir=/var/log/kubernetes –v=2”
启动服务并设置为开机启动
systemctl start kube-apiserver.service
systemctl enable kube-apiserver.service
然后同样把kube-controller-manage和kube-scheduler也都设置为服务和自动启动。
cat /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
Type=notify
EnvironmentFile=/home/eos-master/kubernetes/controller-manager
ExecStart=/usr/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
cat /home/eos-master/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS=”–master=http://127.0.0.1:8080 –logtostderr=false –log-dir=/var/log/kubernetes –v=2”
cat <<EOF>> /usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Scheduler
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
Type=notify
EnvironmentFile=/home/eos-master/kubernetes/scheduler
ExecStart=/usr/bin/kube-scheduler $KUBE_SCHEDULER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF>> /home/eos-master/kubernetes/scheduler
KUBE_SCHEDULER_ARGS="--master=http://127.0.0.1:8080 --logtostderr=false --log-dir=/var/log/kubernetes --v=2"
EOF
然后可以启动服务了
systemctl daemon-reload
systemctl start kube-controller-manager.service
systemctl enable kube-controller-manager.service
systemctl start kube-scheduler.service
systemctl enable kube-scheduler.service
3、安装Kubernetes Node 结点
1、安装docker
yum install -y docker
system启动docker服务
systemctl start docker
systemctl enable docker
2、安装Kuberlet
vi /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=/home/eos-master/kubernetes/kubelet
ExecStart=/usr/bin/kubelet $KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
KUBELET_ARGS=”–api-servers=http://192.168.199.161:8080 –hostname-override=192.168.199.161 –logtostderr=false –log-dir=/var/log/kubernetes –v=2”
3、部署kube-proxy服务
vi /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-proxy Server
After=network.target
Requires=network.target
[Service]
EnvironmentFile=/home/eos-master/kubernetes/kubeproxy
ExecStart=/usr/bin/kube-proxy $KUBELET_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
vi /home/eos-master/kubernetes/kubeproxy
KUBE_PROXY_ARGS=”–master=http://192.168.199.161:8080 –logtostderr=false –log-dir=/var/log/kubenetes –v=2”
kubectl get pods –namespace kube-system
更多推荐
所有评论(0)