操作系统:
CentOS 7
KV存储系统,用于集群的共享配置和服务发现(类似ZooKeeper):
etcd 3.1.0
容器管理工具:
Kubernetes 1.5.2
应用容器引擎
Docker 1.12.6
网络规划工具,统一分配集群Docker容器的虚拟IP,并实现服务之间通信:
Flannel 0.7.0
服务器 | 服务 |
---|---|
master | apiserver, controller-manager, scheduler |
node | flannel, docker, kubelet, kube-proxy |
etcd | etcd |
192.168.89.133
master
192.168.89.133
etcd
192.168.89.134
node1
systemctl stop firewalld.service
systemctl disable firewalld.service
/etc/selinux/config
SELINUX=disabled
reboot
yum install etcd -y
修改/etc/etcd/etcd.conf
中的部分属性
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379"
PS:其中etcd
表示etcd服务器主机名
systemctl start etcd
systemctl enable etcd
etcdctl -C 192.168.89.133:2379 set /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
PS:其中网络号172.17.0.0/16
与docker中的docker0网络一致(若不一致,可修改docker0网络或者配置上述etcd网络);atomic.io
与下面的Flannel配置中的FLANNEL_ETCD_PREFIX
对应
yum install kubernetes-master
修改/etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://etcd:2379"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
PS:测试时需要把KUBE_ADMISSION_CONTROL
中的SecurityContextDeny
和ServiceAccount
去掉,这是权限相关的
修改/etc/kubernetes/config
KUBE_MASTER="--master=http://master:8080"
systemctl enable kube-apiserver kube-scheduler kube-controller-manager
systemctl start kube-apiserver kube-scheduler kube-controller-manager
访问http://master:8080会返回json描述信息,如下图:
yum install docker
yum install flannel
修改/etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
PS:其中atomic.io
与上面etcd中的Network
对应
yum install kubernetes-node
修改/etc/kubernetes/config
KUBE_MASTER="--master=http://master:8080"
修改/etc/kubernetes/kubelet
KUBELET_HOSTNAME="--hostname-override=node1"
KUBELET_API_SERVER="--api-servers=http://master:8080"
systemctl enable kubelet kube-proxy
systemctl start kubelet kube-proxy
在master节点运行
kubectl get nodes
若正常工作,可获取工作节点信息及运行状态为Ready,如下图:
kubectl create -f nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-pod 0/1 ContainerCreating 0 6s
等10分钟再试
NAME READY STATUS RESTARTS AGE
nginx-pod 1/1 Running 0 13m
PS:这里经常会因为网络问题失败,可以先使用docker手动pull镜像后再使用kubectl来create pod,如果还是不行,就delete pod之后再create pod,实在不行,可以重启机器试试,还是不行,那就是配置出问题了
kubectl create -f nginx-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-rc
spec:
replicas: 1
selector:
name: nginx-pod
template:
metadata:
labels:
name: nginx-pod
spec:
containers:
- name: nginx-pod
image: nginx
ports:
- containerPort: 80
kubectl create -f nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
selector:
name: nginx-pod
PS:其中Kubernetes服务为Kube系统自带服务,无需理会
Kubernetes 1.5部署安装dashboard
Kubernetes中的nodePort,targetPort,port的区别和意义
西楼:https://my.oschina.net/zhougui/blog/824165
督门提酒的博客:
http://blog.csdn.net/u010884123/article/details/56485246?locationNum=10&fps=1
https://github.com/HeYongbiao/kube_nginx
kubernetes指南:http://pan.baidu.com/s/1gfKHDAF 密码:who6