在K8S上安装nacos

在K8S上安装nacos

标签: k8s  

[TOC]

下载

git clone https://github.com/nacos-group/nacos-k8s.git

安装nfs

yum -y install nfs-utils rpcbind
systemctl enable rpcbind nfs-server nfs-lock nfs-idmap
echo "/data/nfs-share *(rw,no_root_squash,sync)" >> /etc/exports
echo "/data/mysql *(rw,no_root_squash,sync)" >> /etc/exports
systemctl start rpcbind nfs-server nfs-lock nfs-idmap

#在其他节点安装nfs客户端
yum install nfs-utils -y

安装nacos

kubectl --kubeconfig=/root/kubeconf-dl-xk label node xkdlk8s02 app=nfs-client-provisioner
kubectl --kubeconfig=/root/kubeconf-dl-xk apply -f deploy/nfs/rbac.yaml
kubectl --kubeconfig=/root/kubeconf-dl-xk apply -f deploy/nfs/deployment.yaml
kubectl --kubeconfig=/root/kubeconf-dl-xk create -f deploy/nfs/class.yaml
kubectl --kubeconfig=/root/kubeconf-dl-xk apply -f deploy/mysql/mysql-nfs.yaml
kubectl --kubeconfig=/root/kubeconf-dl-xk apply -f deploy/nacos/nacos-quick-start.yaml 

配置文件

t@ycyl01:~/nacos-k8s# cat deploy/nfs/deployment.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: nfs-client-provisioner
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccount: nfs-client-provisioner
      containers:
      - name: nfs-client-provisioner
        image: registry.cn-hangzhou.aliyuncs.com/open-ali/nfs-client-provisioner:latest
        volumeMounts:
        - name: nfs-client-root
          mountPath: /persistentvolumes
        env:
        - name: PROVISIONER_NAME
          value: fuseim.pri/ifs
        - name: NFS_SERVER
          value: 10.3.32.191
        - name: NFS_PATH
          value: /data/nfs-share
      volumes:
      - name: nfs-client-root
        nfs:
          server: 10.3.32.191
          path: /data/nfs-share

#######
root@ycyl01:~/nacos-k8s# cat deploy/mysql/mysql-nfs.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  replicas: 1
  selector:
    name: mysql
  template:
    metadata:
      labels:
        name: mysql
    spec:
      containers:
      - name: mysql
        image: nacos/nacos-mysql:5.7
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: mysql-data
          mountPath: /var/lib/mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        - name: MYSQL_DATABASE
          value: "nacos_devtest"
        - name: MYSQL_USER
          value: "nacos"
        - name: MYSQL_PASSWORD
          value: "nacos"
      volumes:
      - name: mysql-data
        nfs:
          server: 10.3.32.191
          path: /data/mysql/
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  ports:
  - port: 3306
    targetPort: 3306
  selector:
    name: mysql


##########
root@ycyl01:~/nacos-k8s# cat deploy/nacos/nacos-quick-start.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  labels:
    app: nacos-headless
spec:
  type: NodePort
  ports:
    - port: 8848
      name: server
      targetPort: 8848
      protocol: TCP
      nodePort: 30001
  selector:
    app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
data:
  mysql.db.name: "nacos_devtest"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
spec:
  serviceName: nacos-headless
  replicas: 3
  template:
    metadata:
      labels:
        app: nacos
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - nacos-headless
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: k8snacos
          imagePullPolicy: Always
          image: nacos/nacos-server:latest
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client
          env:
            - name: NACOS_REPLICAS
              value: "3"
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.password
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: NACOS_SERVERS
              value: "nacos-0.nacos-headless.default.svc.cluster.local:8848 nacos-1.nacos-headless.default.svc.cluster.local:8848 nacos-2.nacos-headless.default.svc.cluster.local:8848"
  selector:
    matchLabels:
      app: nacos

访问 ip+30001/nacos

参考 https://blog.csdn.net/qq_33619378/article/details/100130292 http://www.fengzhihai.cn/2020/03/17/k8s-nacos/ http://www.manongjc.com/detail/14-zkgswkobjwsyjiu.html https://www.bbsmax.com/A/A7zgKk9nz4/

「真诚赞赏,手留余香」

Uwei

请我喝杯咖啡?

使用微信扫描二维码完成支付

相关文章