# singlenode-sentinel

* 日志存储采用 hostpath 方式
* Pod 多节点反亲和性调度，单节点失效
* Node 调度， 只运行在指定的节点上
* 由于默认是保存在内存，重启失效，最好的办法修改源码，结合 nacos 持久化(略)



```yaml
[root@master test]# cat singlenode-sentinel-statefulset.yaml 
# 做不到持久化，服务重启，规则丢失，最好的办法修改源码，结合 nacos 持久化
#外部web访问服务
apiVersion: v1
kind: Service
metadata:
  labels:
    app: sentinel
  name: sentinel-node
spec:
  type: NodePort
  ports:
    - name: "web"
      port: 8858
      targetPort: 8858
      nodePort: 30858
  selector:
    app: sentinel
---
# 内部访问服务
apiVersion: v1
kind: Service
metadata:
  name: sentinel-headless
  labels:
    app: sentinel
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - name: web
      port: 8858
      targetPort: 8858
    - name: api
      port: 8719
      targetPort: 8719
      
  selector:
    app: sentinel
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sentinel
  labels:
    app: sentinel
spec:
  serviceName: sentinel-headless
  replicas: 1
  selector:
    matchLabels:
      app: sentinel
  template:
    metadata:
      labels:
        app: sentinel
    spec:
      # 节点打上中间件标签并污染：kubectl taint nodes <node-name> middleware=true:NoSchedule
      #tolerations:
      #  - key: "middleware"
      #    operator: "Equal"
      #    value: "true"
      #    effect: "NoSchedule"
      
      # 当多节点生效：不允许同一个pod调度到同一个节点
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - middleware
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: sentinel
          image: bladex/sentinel-dashboard:1.8.6
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: "1Gi"
              cpu: "1"
          env:
            - name: TZ
              value: America/Sao_Paulo # 巴西: America/Sao_Paulo; 上海：Asia/Shanghai
            - name: JAVA_OPT_EXT
              value: -Dserver.servlet.session.timeout=7200
            - name: SERVER_HOST
              value: -Dcsp.sentinel.dashboard.server=sentinel-headless:8858
            - name: SERVER_PORT
              value: -Dserver.port=8858
            - name: SERVER_API
              value: -Dcsp.sentinel.api.port=8719
          ports:
            - containerPort: 8858
            - containerPort: 8719
          volumeMounts:
            - name: sentinel-log
              mountPath: /opt/logs
      volumes:
        - name: sentinel-log
          hostPath:
            path: /data/k8s/sentinel/
```
