Kubernets
Google公司开源的大规模容器集群管理系统,为容器化应用提供资源调试、部署、服务发现、扩展机制等功能。
ovs(Open VSwitch)
开源的高质量,多层虚拟交换机,目的是让大规模网络自动化可以通过编程扩展。
docker
开源引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。
etcd
用于共享配置和服务发现的分布式,一致性的KV存储系统。
三台CentOS 7虚拟机,设置网卡名为eth0
master 上装Kubernetes(version 1.5.2),etcd(version 3.1.9)。
slave 上装Kubernetes(version 1.5.2),OpenVSwitch(version 2.5.3),Docker(version 1.12.6)。
同时关闭防火墙,关闭SELinux。
[root@master ~]# chkconfig etcd on
[root@master ~]# chkconfig kube-apiserver on
[root@master ~]# chkconfig kube-scheduler on
[root@master ~]# chkconfig kube-controller-manager on
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
KUBE_CONTROLLER_MANAGER_ARGS="--node-monitor-grace-period=10s --pod-eviction-timeout=10s"
[root@master ~]# service etcd restart
[root@master ~]# service kube-apiserver restart
[root@master ~]# service kube-scheduler restart
[root@master ~]# service kube-controller-manager restart
注:所有不指定slave的行为均是在两台上都进行的操作。
[root@slave ~]# chkconfig kube-proxy on
[root@slave ~]# chkconfig kubelet on
[root@slave ~]# chkconfig docker on
[root@slave ~]# chkconfig ovs-vswitchd on
KUBE_MASTER="--master=http://172.17.1.101:8080"
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=172.17.1.121/122" #各自ip
KUBELET_API_SERVER="--api-servers=http://172.17.1.101:8080"
[root@slave ~]# service kube-proxy restart
[root@slave ~]# service kubelet restart
[root@slave1 ~]# vim /etc/docker/daemon.json
{
"bip": "172.27.1.1/24"
}
[root@slave1 ~]# service docker restart
[root@slave2 ~]# vim /etc/docker/daemon.json
{
"bip": "172.27.2.1/24"
}
[root@slave2 ~]# service docker restart
[root@slave ~]# ovs-vsctl add-br k8sbr0
[root@slave1 ~]# ovs-vsctl add-port k8sbr0 vx1 -- set interface vx1 type=vxlan options:remote_ip=172.17.1.122
[root@slave1 ~]# brctl addif docker0 k8sbr0
[root@slave2 ~]# ovs-vsctl add-port k8sbr0 vx1 -- set interface vx1 type=vxlan options:remote_ip=172.17.1.121
[root@slave2 ~]# brctl addif docker0 k8sbr0
[root@slave1 ~]# ip route add 172.27.2.0/24 via 172.17.1.121 dev eth0
[root@slave1 ~]# vim /etc/sysconfig/network-scripts/route-eth0
172.27.2.0/24 via 172.17.1.121 dev eth0
[root@slave2 ~]# ip route add 172.27.1.0/24 via 172.17.1.122 dev eth0
[root@slave2 ~]# vim /etc/sysconfig/network-scripts/route-eth0
172.27.1.0/24 via 172.17.1.122 dev eth0
[root@slave1 ~]# ping 172.27.2.1
PING 172.27.2.1 (172.27.2.1) 56(84) bytes of data.
64 bytes from 172.27.2.1: icmp_seq=1 ttl=64 time=0.274 ms
64 bytes from 172.27.2.1: icmp_seq=2 ttl=64 time=0.216 ms
64 bytes from 172.27.2.1: icmp_seq=3 ttl=64 time=0.218 ms
[root@slave2 ~]# ping 172.27.1.1
PING 172.27.1.1 (172.27.1.1) 56(84) bytes of data.
64 bytes from 172.27.1.1: icmp_seq=1 ttl=64 time=0.320 ms
64 bytes from 172.27.1.1: icmp_seq=2 ttl=64 time=0.208 ms
64 bytes from 172.27.1.1: icmp_seq=3 ttl=64 time=0.338 ms
[root@master ~]# kubectl get node
NAME STATUS AGE
172.17.1.121 Ready 2d
172.17.1.122 Ready 2d
[root@master ~]# vim web-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: webserver
labels:
app: web
spec:
containers:
- name: nginx-server
image: nginx
ports:
- containerPort: 88
[root@master ~]# kubectl create -f web-pod.yaml
[root@master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
webserver 1/1 Running 1 13m 172.27.1.2 172.17.1.121