本文是基于http://www.cnblogs.com/LinuxGo/p/5729788.html 工作的基础上,针对新的版本存在的一些问题做了修改
环境信息
版本信息
组件 | 版本 |
etcd | 3.1.0 |
Flannel | 0.5.5 |
Kubernetes | 1.6.0alpha |
主机信息
主机 | IP | OS |
k8s-master | 172.16.203.133 | Ubuntu 16.04 |
k8s-node01 | Ubuntu 16.04 |
安装Docker
每台主机上安装最新版Docker Engine -https://docs.docker.com/engine/installation/linux/ubuntu/
部署etcd集群
我们将在1台主机上安装部署etcd集群
下载etcd
在部署机上下载etcd
ETCD_VERSION=${ETCD_VERSION:-"3.1.0"} ETCD="etcd-v${ETCD_VERSION}-linux-amd64" curl -L https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/${ETCD}.tar.gz -o etcd.tar.gz tar xzf etcd.tar.gz -C /tmp cd /tmp/etcd-v${ETCD_VERSION}-linux-amd64 sudo mkdir -p /opt/bin && sudo mv * /opt/bin
配置etcd服务
在每台主机上,分别创建/opt/config/etcd.conf和/lib/systemd/system/etcd.service文件,(注意修改红色粗体处的IP地址)
/opt/config/etcd.conf
sudo mkdir -p /var/lib/etcd/ mkdir -p /opt/config/ sudo cat <<EOF | tee /opt/config/etcd.conf ETCD_DATA_DIR=/var/lib/etcd.etcd ETCD_NAME=$(hostname) ETCD_INITIAL_CLUSTER=master=http://172.16.203.133:2380 ETCD_INITIAL_CLUSTER_STATE=new ETCD_LISTEN_PEER_URLS=http:172.16.203.133:2380 ETCD_INITIAL_ADVERTISE_PEER_URLS=http:172.16.203.133:2380 ETCD_ADVERTISE_CLIENT_URLS=http:172.16.203.133:2379 ETCD_LISTEN_CLIENT_URLS=http:172.16.203.133:2379 GOMAXPROCS=$(nproc) EOF
/lib/systemd/system/etcd.service
[Unit] Description=Etcd Server Documentation=https:github.com/coreos/etcd After=network.target [Service] User=root Type=simple EnvironmentFile=-/opt/config/etcd.conf ExecStart=/opt/bin/etcd Restart=on-failure RestartSec=10s LimitNOFILE=40000 [Install] WantedBy=multi-user.target
配置kube-apiserver服务
我们使用如下的Service以及Flannel的网段:
SERVICE_CLUSTER_IP_RANGE=172.18.0.0/16
FLANNEL_NET=192.168.0.0/16
在master主机上,创建/lib/systemd/system/kube-apiserver.service文件,内容如下
[Unit] Description=Kubernetes API Server Documentation=https:github.com/kubernetes/kubernetes After=network.target [Service] User=root ExecStart=/opt/bin/kube-apiserver \ --insecure-bind-address=0.0.0.0 \ --insecure-port=8080 \ --etcd-servers=http:172.16.203.133:2379\ --logtostderr=true \ --allow-privileged=false \ --service-cluster-ip-range=172.18.0.0/16 \ --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,SecurityContextDeny,ResourceQuota \ --service-node-port-range=30000-32767 \ --advertise-address=172.16.203.133 \ --client-ca-file=/srv/kubernetes/ca.crt \ --tls-cert-file=/srv/kubernetes/server.crt \ --tls-private-key-file=/srv/kubernetes/server.key Restart=on-failure Type=notify LimitNOFILE=65536 [Install] WantedBy=multi-user.target
启动服务
sudo systemctl enable kubelet
sudo systemctl start kubelet
配置kube-proxy服务
/lib/systemd/system/kube-proxy.service,注意修改IP地址
[Unit] Description=Kubernetes Proxy After=network.target [Service] ExecStart=/opt/bin/kube-proxy \ --172.16.203.133 \ --master=http:true Restart=on-failure [Install] WantedBy=multi-user.target
配置kubectl
cd /tmp
mv kubernetes/kubectl /usr/bin/kubectl
mkdir -p ~/.kube
vi ~/.kube/config
Version: v1 clusters: - cluster: certificate-authority: crts/ca.crt server: https://172.16.203.133:6443 name: minikube - cluster: insecure-skip-tls-verify: true server: http://172.16.203.133:8080 name: ubuntu contexts: - context: cluster: minikube user: minikube name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube user: client-certificate: crts/server.crt client-key: crts/server.key
done
ps: 感谢Linux&GO的详细文档!!