centos上安装Kubernetes和docker

整理资料时,无意发现早期安装kubernetes和docker的记录,常言说得好,好记性不如烂笔头。

注:由于kubernetes一直更新,故我的笔记未必适用新版kubernetes

软件组件的版本如下:

etcd : 2.3.7

flannel : 0.5.3
Kubernetes: 1.2.0
docker : 1.10.3

  1. 安装centos7操作系统(略,自行搜索),手工配置ip(vi /etc/sysconfig/network-scripts/ifcfg-ens33),保证联网的情况下执行
    yum -y install net-tools

  2.  环境配置 

              2.1  关闭防火墙

                    

1 # systemctl stop firewalld.service    #停止firewall
2 # systemctl disable firewalld.service #禁止firewall开机启动

              2.2  安装NTP并确保正常运行

                  

 # yum -y install ntp
  
 # systemctl start ntpd
 
 # systemctl enable ntpd

               2.3 安装iptables(可选)

      

# yum install -y iptables-services     #安装
# systemctl start iptables.service  #最后重启防火墙使配置生效
# systemctl enable iptables.service #设置防火墙开机启动

 

           3.  master安装配置(先安装yum install libdevmapper* -y)

             

 root@localhost ~]# cd /usr/lib64/
[root@localhost lib64]# rm -rf libgudev-1.0.so.0
[root@localhost lib64]# rm -rf libgudev-1.0.so.0.2.0
[root@localhost lib64]# ln -s  libgudev-1.0.so.0.1.3(需要上传) libgudev-1.0.so.0
[root@localhost lib64]# systemctl start NetworkManager.service

  3.1  安装并配置Kubernetes master(yum 方式)

             

# yum -y install etcd flannel kubernetes

  

3.1.1 修改配置文件/etc/etcd/etcd.conf,确保etcd监听所有地址
# vi /etc/etcd/etcd.conf
# [member]
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
#[cluster]
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

3.1.2 修改配置文件/etc/kubernetes/apiserver
KUBE_API_ADDRESS="--address=0.0.0.0"

KUBE_API_PORT="--port=8080"

KUBELET_PORT="--kubelet_port=10250"

KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:2379"

KUBE_SERVICE_ADDRESSES="--portal_net=10.254.0.0/16"

KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount(可选),ResourceQuota"

#KUBE_ADMISSION_CONTROL="--admission_control=NamespaceAutoProvision,LimitRanger,ResourceQuota"

KUBE_API_ARGS=""
3.1.3 修改配置文件/etc/kubernetes/controller-manager,定义minions ip地址(可选)
KUBELET_ADDRESSES="--machines=172.16.200.130,172.16.200.131,172.16.200.132"

3.1.4 启动服务

for SERVICES in etcd flanneld kube-apiserver kube-controller-manager kube-scheduler; do

systemctl restart $SERVICES

systemctl enable $SERVICES

systemctl status $SERVICES

done

3.1.5 定义flannel网络配置到etcd,这个配置会推送到各个minions的flannel服务上

etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

 

3.2 安装Kubernetes Minions (Nodes先安装yum install libdevmapper* -y)
root@localhost ~]# cd /usr/lib64/
[root@localhost lib64]# rm -rf libgudev-1.0.so.0
[root@localhost lib64]# rm -rf libgudev-1.0.so.0.2.0
[root@localhost lib64]# ln -s libgudev-1.0.so.0.1.3(需要上传) libgudev-1.0.so.0
[root@localhost lib64]# systemctl start NetworkManager.service

vi /etc/selinux/config
#SELINUX=enforcing
SELINUX=disabled

3.2.1 安装flannel和kubernetes
yum -y install flannel kubernetes

3.2.2 为etcd服务配置flannel,修改配置文件 /etc/sysconfig/flanneld

FLANNEL_ETCD="http://172.16.200.129:2379"(172.16.200.129为master ip)


3.2.3 修改kubernetes配置文件,指定master /etc/kubernetes/config

KUBE_MASTER="--master=http://172.16.200.129:8080" (172.16.200.129为master ip)


3.2.4 配置kubelet服务。/etc/kubernetes/kubelet

minions1:

###
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname_override=172.16.200.130"(minion ip)
KUBELET_API_SERVER="--api_servers=http://172.16.200.129:8080" (172.16.200.129为master ip)
KUBELET_ARGS=""

3.2.5 启动kube-proxy, kubelet, docker 和 flanneld services服务,并设置开机自启
# for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done

4.  测试,执行部分命令

 1       kubectl -s 172.16.200.129:8080 version
 2       kubectl -s 172.16.200.129:8080 create -f tomcat.yaml
 3       kubectl -s 172.16.200.129:8080 describe rc  tomcat
 4       kubectl -s 172.16.200.129:8080 describe pod tomcat
 5       kubectl -s 172.16.200.129:8080 get nodes
 6       kubectl -s 172.16.200.129:8080 get namespace
 7       kubectl -s 172.16.200.129:8080 get pod -o wide
 8       kubectl -s 172.16.200.129:8080 get rc -o wide
 9       kubectl -s 172.16.200.129:8080 get svc -o wide
10       kubectl -s 172.16.200.129:8080 get ep -o wide
11       
12       kubectl -s 172.16.200.129:8080 describe rc dongguangming  --namespace=kube-system
13       kubectl -s 172.16.200.129:8080 describe pod  dongguangming  --namespace=kube-system
14 
15       POD_IP=`kubectl -s 172.16.200.129:8080 get ep tomcat -o jsonpath={.subsets[*].addresses[*].ip}`
16       echo $POD_IP
17       curl $POD_IP:8080
18       
19       kubectl -s http://172.16.200.129:8080 describe pod nginx-rc 2>/dev/null | grep Node
20       kubectl -s http://172.16.200.129:8080 describe service nginx-rc 2>/dev/null | grep NodePort

 

 

5.  参考文献:

http://www.cnblogs.com/ilinuxer/p/5866915.html
http://www.ailab.cn/article/2015082028904.html(*******)
http://www.open-open.com/lib/view/open1417658852542.html
非常好:http://www.sunmite.com/linux/installing-kubernetes-cluster-on-centos7-to-manage-pods-and-services/(******************)
http://www.bubuko.com/infodetail-1305310.html(******)
http://blog.csdn.net/felix_yujing/article/details/51621866
http://netmark.jp/2014/12/kubernetes-flannel-centos7-4.html
http://severalnines.com/blog/installing-kubernetes-cluster-minions-centos7-manage-pods-services
http://containertutorials.com/get_started_kubernetes/k8s_example.html
http://www.yesodweb.com/blog/2015/12/yesod-hosting-docker-kubernetes
https://coreos.com/kubernetes/docs/latest/deploy-workers.html
http://www.dasblinkenlichten.com/kubernetes-101-networking/
http://www.yongbok.net/blog/google-kubernetes-container-cluster-manager/
http://zh.hortonworks.com/blog/docker-kubernetes-apache-hadoop-yarn/
http://www.csdn.net/article/2015-06-12/2824937(Kubernetes应用部署模型解析(部署篇))
http://blog.coocla.org/kubernetes-container-monitor.html(Kubernetes技术研究容器监控监测)
http://tonybai.com/2016/11/17/nginx-config-hot-reloading-approach-for-kubernetes-cluster/ (Kubernetes集群中的Nginx配置热更新方案)
https://segmentfault.com/a/1190000002886795(gcr.io/google_containers/pause问题)
http://blog.csdn.net/horsefoot/article/details/52221154(Kubernetes1.3新特性:POD中的初始化容器)
http://news.tuxi.com.cn/news/119999990123105/31054202.html
https://severalnines.com/blog/installing-kubernetes-cluster-minions-centos7-manage-pods-services
https://keithtenzer.com/2015/04/15/containers-at-scale-with-kubernetes-on-openstack/
http://blog.csdn.net/xinghun_4/article/details/50492041(kubernetes中port、target port、node port的对比分析,以及kube-proxy代理)

posted @ 2020-03-26 23:51  董广明  阅读(781)  评论(0编辑  收藏  举报