侧边栏壁纸
博主头像
爱运维 博主等级

行动起来,活在当下

  • 累计撰写 197 篇文章
  • 累计创建 143 个标签
  • 累计收到 21 条评论

目 录CONTENT

文章目录
K8S

kubernetes使用动态存储挂载nfs并部署consul

Administrator
2019-08-29 / 0 评论 / 0 点赞 / 4 阅读 / 0 字

1.在nfs主机192.168.3.22上启动nfs

mkdir -p /hbase_data/consul_data_pv1

vim /etc/exports
/filedata 192.168.3.0/24(rw,sync,no_root_squash)
/filedata 192.168.33.0/24(rw,sync,no_root_squash)
/hbase_data/consul_data_pv1 *(rw,no_root_squash,sync)

exportfs -r
systemctl restart rpcbind && systemctl restart nfs

2.进入k8s集群192.168.3.18上创建动态存储类

mkdir /lvqingshan/consul/nfs
创建rbac
vim rbac.yaml
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-provisioner-runner
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-provisioner
subjects:
- kind: ServiceAccount
name: nfs-provisioner
namespace: default
roleRef:
kind: ClusterRole
name: nfs-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-provisioner
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-provisioner
subjects:
- kind: ServiceAccount
name: nfs-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: Role
name: leader-locking-nfs-provisioner
apiGroup: rbac.authorization.k8s.io
创建serviceaccount
vim serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-provisioner
创建nfs-client-provisioner
vim deployment.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: nfs-provisioner
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: nfs-provisioner
spec:
containers:
- name: nfs-provisioner
image: registry.cn-hangzhou.aliyuncs.com/open-ali/nfs-client-provisioner
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: example.com/nfs
- name: NFS_SERVER
value: 192.168.3.22
- name: NFS_PATH
value: /hbase_data/consul_data_pv1
volumes:
- name: nfs-client-root
nfs:
server: 192.168.3.22
path: /hbase_data/consul_data_pv1
创建nfs-storageclass
vim nfs-storageclass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: nfs
provisioner: example.com/nfs
kubectl create -f rbac.yaml
kubectl create -f serviceaccount.yaml
kubectl create -f deployment.yaml
kubectl create -f nfs-storageclass.yaml

3.测试用动态存储类创建pvc

vim test-pvc1.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-default-consul-consul-server-1
spec:
accessModes:
- ReadWriteOnce
storageClassName: rbd
resources:
requests:
storage: 3Gi
kubectl create -f test-pvc1.yaml
查看是否创建成功,然后删除
kubectl delete -f test-pvc1.yaml

4.在consul在kubernetes中部署

mkdir /consul
cd /consul
git clone https://github.com/hashicorp/consul-helm.git
修改values.yaml
vim consul-helm/values.yaml
开起service
# enabled: false
enabled: true
注释掉ClusterIP
#type: ClusterIP
使用NodePort
type: NodePort
nodePort: 40213
ui改为
type: NodePort
修改storageClass为之前创建的,默认大小为10G可以不用修改
storageClass: nfs
部署consul
helm install --name consul ./consul-helm

5.consul备份

vim backup.sh
#!/bin/sh
DATE=`date +%Y%m%d%H%M`

export CONSUL_HTTP_ADDR="192.168.3.21:28501"
export CONSUL_HTTP_TOKEN="9f012e18-1a62-4a0a-4d8e-f6ef9f45c689"

echo $CONSUL_HTTP_ADDR
echo $CONSUL_HTTP_TOKEN

consul kv export > /root/xiaochen-toolkit/scripts/consul/backup_data/kv.dump.$DATE
consul snapshot save /root/xiaochen-toolkit/scripts/consul/backup_data/backup.snap.$DATE
0

评论区