---
apiVersion: v1
kind: Service
metadata:
  name: nacos-svc
  labels:
    app: nacos-svc
spec:
  type: NodePort
  ports:
    - port: 8848
      name: server
      targetPort: 8848
      nodePort: 30848
  selector:
    app: nacos-standalone
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-server
  labels:
    app: nacos-server
spec:
  type: ClusterIP
  ports:
    - port: 8848
      name: server
      targetPort: 8848
    - port: 9848
      name: client-rpc
      targetPort: 9848
    - port: 9849
      name: raft-rpc
      targetPort: 9849
    - port: 7848
      name: old-raft-rpc
      targetPort: 7848
  selector:
    app: nacos-standalone
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
data:
  mysql.host: 'nacos-mysql'
  mysql.db.name: 'nacos_config
  mysql.port: '3307'
  mysql.user: 'nacos'
  mysql.password: 'nacos'
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nacos-standalone
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nacos-standalone
      annotations:
        pod.alpha.kubernetes.io/initialized: 'true'
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: 'app'
                    operator: In
                    values:
                      - nacos-standalone
              topologyKey: 'kubernetes.io/hostname'
      containers:
        - name: local-nacos
          imagePullPolicy: Always
          image: registry.cn-hangzhou.aliyuncs.com/sca-community/nacos-server
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc
          env:
            - name: SPRING_DATASOURCE_PLATFORM
              value: "mysql"
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.host
            - 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: PREFER_HOST_MODE
              value: 'hostname'
  selector:
    matchLabels:
      app: nacos-standalone

