Docker(二十) consul 在公有云1分钟部署(腾讯云)

其实很简单利用helm 直接安装


helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul
helm install --name consul --namespace=consul stable/consul

helm install --name consul --namespace=consul stable/consul

然后等一分钟就安装好了

web管理界面可以通过svc 对外的8500端口来访问


另外写下之间手动写的编排文件

consul_service.yml

consul_service.yml

apiVersion: v1
kind: Service
metadata:  
    name: stag-consul  
    labels:    
      name: stag-consul
spec:  
    type: ClusterIP  
    ports:    
     - name: http      
       port: 8500      
       targetPort: 8500    
     - 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: stag-consul
    clusterIP: None

consul_statefulset.yml

apiVersion: apps/v1beta1 
kind: StatefulSet
metadata:
  name: stag-consul
spec:
  serviceName: stag-consul
  replicas: 3
  template: 
    metadata:
      labels:
        app: stag-consul
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - stag-consul
              topologyKey: kubernetes.io/hostname
      terminationGracePeriodSeconds: 10
      containers:
      - name: consul
        image: consul:latest
        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=stag-consul"
            # - "-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"
        volumeMounts:
            - name: data
              mountPath: /consul/data
        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
      volumes:
        - name: data
          hostPath:
            path: /home/consuldata

这里有个问题,因为consul是有状态服务,所有必须用pvc 来进行存储,我这里为了方便,直接挂在了hostpath,后续更新storageclass的方式

上一篇:部署Jenkins


下一篇:CentOS7.6安装稳定版Nginx