K8S+docker微服务部署架构描述:1台master node,2台slave node
安装Docker
1. root账户登录,查看系统内核版本(ubuntu内核3.8+,Centos 6.5+)
# uname -a
2. 升级yum包到最新(可选)
# yum update
卡通可爱3. 设置yum源
4. 查看仓库中的docker版本,选择特定版本安装
# yum list docker-ce --showduplicates | sort -r
5. 安装Docker,命令:yum installdocker-ce-版本号
# yum install docker-ce-17.
6. 启动Docker
# systemctl start docker
# systemctl enable docker
7. 检查是否安装成功(有client和rvice两部分表⽰docker安装启动成功)
# docker version
8. 开启Docker远程访问
# vim/lib/systemd/system/docker.rvice
ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock#
# systemctldaemon-reload
# systemctlrestart docker
验证
在Docker主机配置远程镜像仓库(registry搭建私有仓库 )
# vi /etc/docker/daemon.json
{
"registry-mirrors": [""],
"incure-registries": ["192.168.1.45:5000"]
}
修改完重启重置复记老友粉
# systemctldaemon-reload
# systemctlrestart docker
# sudorvice docker status
其他相关命令
英语小短剧# docker stop docker --停⽌docker
# docker restart docker --重启docker
# docker ps --查看正在运⾏的容器
链接英文
# docker ps -a --查看所有容器的状态
# docker images --查看本地镜像
# docker rm id/name --删除某个容器
垃圾怎么画
# docker rmi id/name --删除某个镜像
# docker build -t eureka:v1 . --通过当前⽬录下的Dockerfile构建⼀个名为eureka:v1的镜像
# docker build -t eureka:v1 -f dockerfile_eureka . --通过指定配置⽂件名构建镜像
# docker run -d -p 1111:1111 --name crm-eureka eureka:v1 --通过镜像构建名为crm-eureka的容器,并以后台模式运⾏
安装kubernets
1. 关闭防⽕墙
# systemctl disable firewalld
# systemctl stop firewalld
# tenforce 0
2. master节点安装etcd和kubernets
# yum install etcd -y
# vi /etc/hosts
10.0.0.11 master
10.0.0.12 node-1
10.0.0.13 node-2
# systemctl restart network
# vi/etc/f
.......
6⾏:ETCD_LISTEN_CLIENT_URLS="0.0.0.0:2379"
21⾏:ETCD_ADVERTISE_CLIENT_URLS="10.0.0.11:2379"
.......
# systemctl start etcd.rvice
# systemctl enable etcd.rvice
检测etcd是否安装成功
# etcdctl t testdir/testkey0 0
# etcdctl get testdir/testkey0
检测健康状态
安装kubernetes
# yum install kubernetes-master.x86_64-y
# yum install etcd -y kubernetes
# vi /etc/kubernetes/apirver
......
8⾏: KUBE_API_ADDRESS="--incure-bind-address=0.0.0.0"
11⾏:KUBE_API_PORT="--port=8080"
23⾏:此处是⼀⾏
KUBE_ADMISSION_CONTROL="--admission-
control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" ......
# vi /etc/kubernetes/config
......
......
3. 启动所有服务
# systemctl enable kube-apirver.rvice
# systemctl start kube-apirver
# systemctl restartkube-apirver.rvice
# systemctl enablekube-controller-manager.rvice
# systemctl restartkube-controller-manager.rvice
# systemctl enablekube-scheduler.rvice
# systemctl restartkube-scheduler.rvice
检查服务是否安装成功
# kubectl get componentstatus
4. node节点安装kubernets
# yum install kubernetes-node.x86_64-y
# vi /etc/kubernetes/config
......
......
# vi /etc/kubernetes/kubelet
......
5⾏:KUBELET_ADDRESS="--address=0.0.0.0"
8⾏:KUBELET_PORT="--port=10250"
11⾏:KUBELET_HOSTNAME="--hostname-override=10.0.0.12" ......
青春时期
# systemctl enable kubelet.rvice
# systemctl start kubelet.rvice
# systemctl enable kube-proxy.rvice
# systemctl start kube-proxy.rvice
在master节点检查node运⾏状态
# kubectl get nodes
描写风景的好词5. 所有节点分别配置flannel⽹络
# yum install flannel -y
#d -i
master节点操作
# etcdctl mk /atomic.io/network/config'{ "Network": "172.16.0.0/16" }' # yum install docker -y
# systemctl enable flanneld.rvice
# systemctl restart flanneld.rvice
# systemctl restart docker
# systemctl enable docker
# systemctl restart kube-apirver.rvice
# systemctl restartkube-controller-manager.rvice
# systemctl restartkube-scheduler.rvice
node节点:node-1 node-2
# systemctl enable flanneld.rvice
# systemctl restart flanneld.rvice
# systemctl restart docker
# systemctl restart kubelet.rvice
# systemctl restart kube-proxy.rvice
所有节点启动docker node-1node-2都部署
#vi/usr/lib/systemd/system/docker.rvice
在[Service]区域下增加⼀⾏
......
[Service]
ExecStartPost=/usr/sbin/iptables -P FORWARDACCEPT
恭喜别人生女儿的祝福语......
# systemctl daemon-reload
# systemctl restart docker
6. 将node加⼊到kubernetes集群中
⾸先在master上执⾏下列命令获取token
# kubeadm token list
(如果过期可先执⾏此命令
# kubeadm token create #重新⽣成token
列出token
# kubeadm token list | awk -F" "'{print $1}' |tail -n 1获取CA公钥的哈希值