sh Kubernetes Auto GlusterFS光伏创建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Kubernetes Auto GlusterFS光伏创建相关的知识,希望对你有一定的参考价值。

#!/bin/bash

glusterName=glusterfs-cluster
glusterEP=10.240.0.10 
glusterNode01Path=gluster01:/storage-pool
glusterNode02Path=gluster02:/storage-pool

while true; do

	check=$(kubectl get pvc --all-namespaces --no-headers |grep Pending | head -1)

        if [[ "$check" != "" ]]; then

		ns=$(echo $check |awk '{print $1}')
		name=$(echo $check |awk '{print $2}')
		checkExist=$(gluster volume list |grep $name)
		volume="$name"

        	if [[ "$checkExist" == "" ]]; then
  			echo ""
			echo "Let's create a Gluster volume ($volume) ..."
		 	size=$(kubectl -n $ns get pvc $name -o json | jq -r .spec.resources.requests.storage)
			sizeGluster=$(echo $size |cut -d 'G' -f1)

			gluster volume create $volume \
			       replica 2 transport tcp \
			       $glusterNode01Path/$volume \
			       $glusterNode02Path/$volume

			gluster volume start $volume

			gluster volume quota $volume enable
			gluster volume quota $volume limit-usage / "$sizeGluster"GB

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: $glusterName
  namespace: $ns
spec:
  clusterIP: None
  ports:
  - port: 1
    protocol: TCP
    targetPort: 1
  sessionAffinity: None
---
apiVersion: v1
kind: Endpoints
metadata:
  name: $glusterName
  namespace: $ns
subsets:
- addresses:
  - ip: $glusterEP
  ports:
  - port: 1
    protocol: TCP
EOF
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: PersistentVolume
metadata:
  name: $volume
spec:
  capacity:
    storage: $size
  accessModes:
    - ReadWriteMany
  glusterfs:
    path: $volume
    endpoints: $glusterName
    readOnly: false
EOF
			echo "$volume of $size is created. "
			echo ""

		else
			echo "$volume already exist.... "
		fi
 	fi

        sleep 5
done

以上是关于sh Kubernetes Auto GlusterFS光伏创建的主要内容,如果未能解决你的问题,请参考以下文章

如何在 AWS EC2 上为 Rancher 和 Kubernetes 集群做 Auto Scaling?

Kubernetes 上的 GitLab Auto DevOps 挂起,网络超时,无法执行 yj

sh kubernetes.sh

sh auto_key_creation.sh

sh canonical-kubernetes-offline-install.sh

sh 新的Kubernetes项目