e. 配置/etc/etcd/etcd.conf:
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
f. 启动服务:
# for SERVICES in kube-apiserver kube-controller-manager kube-scheduler; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
3. 配置Minion:
a. yum install docker-io kubernetes-client kubernetes-node
b. 配置 /etc/kubernetes/kubelet:
KUBELET_ADDRESS="--address=0.0.0.0"
# KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=172.16.9.158"
KUBELET_API_SERVER="--api-servers=http://172.16.9.158:8080"
KUBELET_ARGS="--pod-infra-container-image=docker.repo:5000/kube/pause:0.8.0"
c. 启动服务:
for SERVICES in kube-proxy kubelet flanneld docker; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
a. yum -y install flannel (在minion节点)
b. 设置通讯子网
etcdctl set /atomic.io/network/config '{"Network":"10.10.0.0/16", "Backend":{"Type":"vxlan"}}' (在master节点)
Kubernetes的持久存储Glusterfs:
在minion节点上:
1. 更改/etc/kubernetes/config为如下内容:
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=true"(此项只有在glusterfs作为kubeneters的pod时使用)
KUBE_MASTER="--master=http://172.16.9.158:8080"
2. 更改/etc/kubernetes/kubelet为如下内容:
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=172.16.9.158"
KUBELET_API_SERVER="--api-servers=http://172.16.9.158:8080"
KUBELET_ARGS="--pod-infra-container-image=docker.repo:5000/kube/pause:0.8.0 \
--register-node=true \
--host-network-sources=*"(此项只有在glusterfs作为kubeneters的pod时使用)
3. 配置glusterfs的yum repo:
cat > glusterfs.repo <<EOF
# Place this file in your /etc/yum.repos.d/ directory
[glusterfs-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/EPEL.repo/epel-$releasever/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/rsa.pub
[glusterfs-noarch-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/EPEL.repo/epel-$releasever/noarch
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/rsa.pub
[glusterfs-source-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes. - Source
baseurl=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/EPEL.repo/epel-$releasever/SRPMS
enabled=0
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/rsa.pub
EOF
4. glusterfs服务端的软件安装:
yum -y install glusterfs-server
5. glusterfs客户端的软件安装:
yum -y install glusterfs glusterfs-fuse
6. 在glusterfs服务端启动glusterd服务:
service glusterd start
7. 配置hosts文件:
a. 在gluster1节点上,配置hosts文件如下:
cat >> /etc/hosts <<EOF
127.0.0.1 gluster1
172.16.12.10gluster2
EOF
b. 在gluster2节点上,配置hosts文件如下:
cat >> /etc/hosts <<EOF
172.16.12.9gluster1
127.0.0.1gluster2
EOF
8. 组建glusterfs集群:
a. gluster peer probe gluster2
b. 查看集群节点状态:
gluster peer status
9. 需要一个独立的分区,用于glusterfs创建数据卷,此处假设为/dev/vdb
a. mkdir /brick;mkfs.xfs /dev/vdb1
b. mount /dev/vdb1 /brick
c. 创建glusterfs卷:
gluster volume create gv1 replica 2 gluster1:/brick/gv1 gluster2:/brick/gv1
d. 启动gv1卷:
gluster volume start gv1
c. 查看gv1卷的状态:
gluster volume info
10. 客户端挂载测试:
a. 客户端先配置好hosts
cat >> /etc/hosts <<EOF
172.16.12.9gluster1
172.16.12.10gluster2
EOF
b. mount -t glusterfs gluster1:/gv1 /mnt
11. 与k8s集成:
a. 创建glusterfs的endpoints(相当于glusterfs文件系统的入口):
cat > glusterfs-endpoints.yml <<EOF
apiVersion: v1
kind: Endpoints
metadata:
name: glusterfs-cluster
subsets:
- addresses:
- ip: 172.16.12.9
ports:
- port: 1
- addresses:
- ip: 172.16.12.10
ports:
- port: 1
EOF
b. 配置glusterfs-endpoints的services:
cat > glusterfs-service.yml <<EOF
apiVersion: v1
kind: Service
metadata:
name: glusterfs-cluster
spec:
ports:
- port: 1
EOF
c. 部署用glusterfs做后端存储的应用,此处用ppc64le/httpd来举例:
cat > apache-deployment.yml <<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: httpd-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: apache
spec:
containers:
- name: apache
image: ppc64le/httpd
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- mountPath: /usr/local/apache2/htdocs
name: glusterfsvol
volumes:
- name: glusterfsvol
glusterfs:
endpoints: glusterfs-cluster
path: gv1
EOF