k8s是部署nacos

2022-09-21 15:11:00
admin
原创
19
摘要:k8s是部署nacos

k8s是部署nacos

1、首先创建一个便签

kubectl label nodes k8s-master-1 zone=file
apiVersion: v1
kind: Service
metadata:
  name: nacos-service-nodeport
  namespace: joker-bladex
spec:
  type: NodePort
  ports:
    - port: 8848
      targetPort: 8848
      nodePort: 30098
      name: server-nodeport
    - port: 9848
      name: server-nodeport-client-rpc
      targetPort: 9848
      nodePort: 30095
    - port: 9849
      name: server-nodeport-raft-rpc
      targetPort: 9849
      nodePort: 30097
    ## 兼容1.4.x版本的选举端口
    - port: 7848
      name: server-nodeport-old-raft-rpc
      targetPort: 7848
      nodePort: 30096
  selector:
    app: nacos
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  namespace: joker-bladex
  labels:
    app: nacos-headless
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 8848
      name: server
      targetPort: 8848
    - port: 9848
      name: client-rpc
      targetPort: 9848
    - port: 9849
      name: raft-rpc
      targetPort: 9849
    ## 兼容1.4.x版本的选举端口
    - port: 7848
      name: old-raft-rpc
      targetPort: 7848
  selector:
    app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
  namespace: joker-bladex
data:
  mysql.db.name: "nacos_devtest"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
  namespace: joker-bladex
spec:
  serviceName: nacos-headless
  replicas: 1
  template:
    metadata:
      labels:
        app: nacos
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - nacos
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: k8snacos
          #image: registry.kubeoperator.io:8083/hiedu/nacos-server:v1.0
          #image: nacos/nacos-server:v2.0.4
          image: nacos/nacos-server:v2.1.0
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc
          env:
            - name: NACOS_REPLICAS
              # 单机模式设置成1,集群模式设置成3
              value: "1"
            - 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: MODE
              value: standalone
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: NACOS_APPLICATION_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: NACOS_SERVERS
              value: "nacos-0.nacos-headless.joker-bladex.svc.cluster.local:8848"
              #nacos-1.nacos-headless.joker-bladex.svc.cluster.local:8848 nacos-2.nacos-headless.joker-bladex.svc.cluster.local:8848"
      nodeSelector:
        zone: nacos 
  selector:
    matchLabels:
      app: nacos

发表评论
评论通过审核之后才会显示。
文章分类
联系方式
联系人: 郑州-小万
电话: 13803993919
Email: 1027060531@qq.com
QQ: 1027060531
网址: www.wanhejia.com