cat <<'END' > consul.yaml
---
apiVersion: v1
kind: Service
metadata:  
  name: consul  
  labels:
    name: consul
spec:  
  type: NodePort
  ports:   
  - name: http    
    port: 8500    
    targetPort: 8500
    nodePort: 31500  
  - name: https    
    port: 8443
    targetPort: 8443
  - name: rpc
    port: 8400
    targetPort: 8400   
  - name: serflan-tcp    
    protocol: "TCP"    
    port: 8301    
    targetPort: 8301   
  - name: serflan-udp    
    protocol: "UDP"    
    port: 8301    
    targetPort: 8301   
  - name: serfwan-tcp    
    protocol: "TCP"    
    port: 8302    
    targetPort: 8302   
  - name: serfwan-udp    
    protocol: "UDP"    
    port: 8302    
    targetPort: 8302
  - name: server    
    port: 8300    
    targetPort: 8300   
  - name: consuldns    
    port: 8600    
    targetPort: 8600  
  selector:   
   app: consul
END
kubectl apply -f consul.yaml

cat <<'END' > consul-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: consul
spec:
  serviceName: consul
  selector:
    matchLabels:
      app: consul
  replicas: 3
  template:
    metadata:
      labels:
        app: consul
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: consul
        image: hub.redblue-ai.com/consul
        args:
        - "agent"
        - "-server"
        - "-bootstrap-expect=3"
        - "-ui"
        - "-data-dir=/consul/data"
        - "-bind=0.0.0.0"
        - "-client=0.0.0.0"
        - "-advertise=$(PODIP)"
        - "-retry-join=consul-0.consul.$(NAMESPACE).svc.cluster.local"
        - "-retry-join=consul-1.consul.$(NAMESPACE).svc.cluster.local"
        - "-retry-join=consul-2.consul.$(NAMESPACE).svc.cluster.local"
        - "-domain=cluster.local"
        - "-disable-host-node-id"
        env:
        - name: PODIP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        ports:
        - containerPort: 8500
          name: ui-port
        - containerPort: 8400
          name: alt-port
        - containerPort: 53
          name: udp-port
        - containerPort: 8443
          name: https-port
        - containerPort: 8080
          name: http-port
        - containerPort: 8301
          name: serflan
        - containerPort: 8302
          name: serfwan
        - containerPort: 8600
          name: consuldns
        - containerPort: 8300
          name: server
        volumeMounts:
        - name: data
          mountPath: /consul/data
  volumeClaimTemplates:
  - metadata:
      name: data
      annotations:
        volume.beta.kubernetes.io/storage-class: "ceph-rbd"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi
END
kubectl apply -f consul-statefulset.yaml

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐