k8s使用glusterfs做持久化存储(十三)
k8s使用glusterfs存储
1.k8s yaml文件帮助查询
[root@k8s-master ~]# kubectl explain pv.spec
语法格式
kubectl explain 资源.命令.命令
2.创建endpoint资源
1)编写yaml文件
[root@k8s-master ~]# mkdir /k8s/glusterfs
[root@k8s-master ~]# cd /k8s/glusterfs
[root@k8s-master glusterfs]# vim glusterfs-ep.yaml
apiVersion: v1
kind: Endpoints
metadata:
name: glusterfs
namespace: default #只能对指定的namespace提供存储服务
subsets:
- addresses:
- ip: 192.168.81.240
- ip: 192.168.81.250
- ip: 192.168.81.136
ports:
- port: 49152
protocol: TCP
2)创建资源
[root@k8s-master glusterfs]# kubectl create -f glusterfs-ep.yaml
endpoints "glusterfs" created
3)查看endpoints资源的信息
[root@k8s-master glusterfs]# kubectl get endpoints
NAME ENDPOINTS AGE
glusterfs 192.168.81.136:49152,192.168.81.240:49152,192.168.81.250:49152 12m
kubernetes 192.168.81.210:6443 19d
mynginx 172.16.83.3:80,172.16.83.4:80,172.16.83.6:80 + 2 more... 8d
mysql 172.16.83.16:3306 5d
mytomcat 172.16.83.5:8080 5d
myweb2 <none> 10d
nginx-proxy-svc 172.16.83.11:80,172.16.83.2:80,172.16.83.8:80 4d
3.创建service资源
endpoint资源要和svc资源关联
1)编写yaml文件
[root@k8s-master glusterfs]# vim glusterfs-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: glusterfs
namespace: default
spec:
ports:
- port: 49152
protocol: TCP
targetPort: 49152
sessionAffinity: None
type: ClusterIP
2)创建资源
[root@k8s-master glusterfs]# kubectl create -f glusterfs-svc.yaml
service "glusterfs" created
3)查看详细信息
[root@k8s-master glusterfs]# kubectl describe svc glusterfs
Name: glusterfs
Namespace: default
Labels: <none>
Selector: <none>
Type: ClusterIP
IP: 10.254.15.38
Port: <unset> 49152/TCP
Endpoints: 192.168.81.136:49152,192.168.81.240:49152,192.168.81.250:49152 #endpoint的地址
Session Affinity: None
No events.
4.创建pv资源
1)编写yaml文件
[root@k8s-master glusterfs]# vim glusterfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: gluster
labels:
type: glusterfs
spec:
capacity:
storage: 30Gi
accessModes:
- ReadWriteMany
glusterfs:
endpoints: "glusterfs"
path: "web_volume01"
readOnly: false
2)创建资源
[root@k8s-master glusterfs]# kubectl create -f glusterfs-pv.yaml
persistentvolume "gluster" created
3)查看信息
[root@k8s-master glusterfs]# kubectl get pv gluster
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
gluster 30Gi RWX Retain Available 1m
5.创建pvc资源
1.编写yaml文件
[root@k8s-master glusterfs]# vim glusterfs-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: gluster
spec:
selector:
matchLabels:
type: glusterfs
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
2.创建资源
[root@k8s-master glusterfs]# kubectl create -f glusterfs-pvc.yaml
persistentvolumeclaim "gluster" created
3.查看信息
[root@k8s-master glusterfs]# kubectl get pvc gluster
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
gluster Bound gluster 30Gi RWX 23s
6.将demo项目的mysql数据库使用glusterfs存储资源
6.1.解决windows编码问题
文件中出现这种^M的编码,这是由于从windows传导致的
解决办法:
[root@k8s-master glusterfs]# yum -y install dos2unix
[root@k8s-master glusterfs]# dos2unix mysql-rc.yml
dos2unix: converting file mysql-rc.yml to Unix format ...
6.2.node节点配置
1)配置hosts解析
[root@k8s-node2 gluster_rpm]# vim /etc/host
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.81.210 k8s-master
192.168.81.220 k8s-node1
192.168.81.230 k8s-node2
192.168.81.240 glusterfs01
192.168.81.250 glusterfs02
192.168.81.136 glusterfs03
2)安装glusterfs
[root@k8s-node1 ~]# tar xf gluster_rpm_el7.tar.gz
[root@k8s-node1 ~]# cd gluster_rpm/
[root@k8s-node1 gluster_rpm]# yum -y localinstall *.rpm
6.3.修改yaml配置文件
[root@k8s-master glusterfs]# vim mysql-rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: 192.168.81.240/k8s/mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: '123456'
volumeMounts:
- name: mysql
mountPath: /var/lib/mysql
volumes:
- name: mysql
persistentVolumeClaim:
claimName: gluster
6.4.更新配置
[root@k8s-master glusterfs]# kubectl apply -f mysql-rc.yaml
目录 返回
首页