K8S安装Apisix,搭建NFS存储

1,027 阅读1分钟

搭建NFS存储

  • 选择一个磁盘比较空的work节点,安装nfs
yum -y install nfs-utils rpcbind

vim /etc/exports
# 放入
/nfsdata *(rw,sync,no_root_squash)

mkdir /nfsdata
systemctl start nfs-server
systemctl start rpcbind
  • 创建rabc授权

nfs-rbac-rolebind.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-provisioner
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
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: ["watch", "create", "update", "patch"]
   -  apiGroups: [""]
      resources: ["services", "endpoints"]
      verbs: ["get","create","list", "watch","update"]
   -  apiGroups: ["extensions"]
      resources: ["podsecuritypolicies"]
      resourceNames: ["nfs-provisioner"]
      verbs: ["use"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-provisioner
    namespace: apisix
roleRef:
  kind: ClusterRole
  name: nfs-provisioner-runner
  apiGroup: rbac.authorization.k8s.io

kubectl apply -f rbac-rolebind.yaml -n apisix

  • 创建nfs-deployment.yaml nfs-deployment.yaml,填入搭建nfs的ip
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  namespace: apisix
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccount: nfs-provisioner
      containers:
        - name: nfs-client-provisioner
          image: registry.cn-hangzhou.aliyuncs.com/open-ali/nfs-client-provisioner
          volumeMounts:
            - name: nfs-client-root
              mountPath:  /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: zjz
            - name: NFS_SERVER
              value: 172.16.xxx.xxx
            - name: NFS_PATH
              value: /nfsdata
      volumes:
        - name: nfs-client-root
          nfs:
            server: 172.16.xxx.xxx
            path: /nfsdata

kubectl apply -f nfs-deployment.yaml

  • 创建 StorageClass nfs-storage.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: stateful-nfs
provisioner: zjz
reclaimPolicy: Retain

kubectl apply -f nfs-storage.yaml

搭建Apisix

拉取文件

helm repo add apisix https://charts.apiseven.com
helm pull apisix apisix/apisix

修改 values.yaml

  ingress:
    enabled: true
    annotations: {}
      # kubernetes.io/ingress.class: nginx
      # kubernetes.io/tls-acme: "true"
    hosts:
      - host: gw.xxxx.com
        paths:
          - /
          
dns:
  resolvers:
    - 192.168.0.xx # k8s的dns地址
  validity: 30
  timeout: 5

修改etcd values.yaml

persistence:
  ## If true, use a Persistent Volume Claim. If false, use emptyDir.
  ##
  enabled: true
  ## Persistent Volume Storage Class
  ## If defined, storageClassName: <storageClass>
  ## If set to "-", storageClassName: "", which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
  ##   GKE, AWS & OpenStack)
  ##
  # storageClass: "stateful-nfs"
  ## Persistent Volume Claim annotations (evaluated as a template)
  ##
  annotations:
    volume.beta.kubernetes.io/storage-class: nas

helm install apisix apisix --namespace apisix --debug

后期变动更新使用

helm upgrade apisix apisix --namespace apisix --debug

image.png