简体   繁体   English

具有共享存储的Kuberenetes上的ActiveMQ

[英]ActiveMQ on Kuberenetes with Shared storage

I have existing applications built with Apache Camel and ActiveMQ. 我有使用Apache Camel和ActiveMQ构建的现有应用程序。 As part of migration to Kubernetes, what we are doing is moving the same services developed with Apache Camel to Kubernetes. 作为迁移到Kubernetes的一部分,我们正在做的是将使用Apache Camel开发的相同服务转移到Kubernetes。 I need to deploy ActiveMQ such that I do not lose the data in case one of the Pod dies. 我需要部署ActiveMQ,这样我就不会丢失数据,以防其中一个Pod死掉。

What I am doing now is running a deployment with RelicaSet value to 2. This will start 2 pods and with a Service in front, I can serve any request while atleast 1 Pod is up. 我现在正在做的是运行一个RelicaSet值为2的部署。这将启动2个pod并且前面有一个Service,我可以在至少1个Pod启动时提供任何请求。 However, if one Pod dies, i do not want to lose the data. 但是,如果一个Pod死了,我不想丢失数据。 I want to implement something like a shared file system between the Pods. 我想在Pod之间实现类似共享文件系统的东西。 My environment is in AWS so I can use EBS. 我的环境在AWS中,所以我可以使用EBS。 Can you suggest, how to achieve that. 你能建议,如何实现这一目标。

Below is my deployment and service YAML. 以下是我的部署和服务YAML。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: smp-activemq
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: smp-activemq
    spec:
      containers:
        - name: smp-activemq
          image: dasdebde/activemq:5.15.9
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 61616
          resources:
            limits:
              memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: smp-activemq
spec:
  type: NodePort
  selector:
    app: smp-activemq
  ports:
    - nodePort: 32191
      port: 61616
      targetPort: 61616

In high-level terms, what you want is a StatefulSet instead of a Deployment for your ActiveMQ. 在高级术语中,您想要的是StatefulSet而不是ActiveMQ的部署。 You are correct that you want "shared file system" -- in kubernetes this is expressed as a " Persistent Volume ", which is made available to the pods in your StatefulSet using a " Volume Mount ". 你是正确的,你想要的“共享文件系统” -在这kubernetes表示为“ 持久卷 ”,这是提供给使用“ 卷装入 ”你StatefulSet豆荚。

These are the things you need to look up. 这些是你需要查找的东西。

StatefulSets are valuable for applications that require stable, persistent storage. StatefulSet对于需要稳定,持久存储的应用程序非常有用。 Deleting and/or scaling a StatefulSet down will not delete the volumes associated with the StatefulSet. 删除和/或缩放StatefulSet将不会删除与StatefulSet关联的卷。 This is done to ensure data safety. 这样做是为了确保数据安全。 The "volumeClaimTemplates" part in yaml will provide stable storage using PersistentVolumes provisioned by a PersistentVolume Provisioner. 在YAML的“volumeClaimTemplates”部分将使用提供稳定的存储PersistentVolumes由PersistentVolume置备供应。

In your case, StatefulSet file definition will look similar to this: 在您的情况下,StatefulSet文件定义将类似于:

apiVersion: v1
kind: Service
metadata:
  name: smp-activemq
  labels:
    app: smp-activemq
spec:
  type: NodePort
  selector:
    app: smp-activemq
  ports:
  - nodePort: 32191
    port: 61616
    name: smp-activemq
    targetPort: 61616

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: smp-activemq
spec:
  selector:
    matchLabels:
      app: smp-activemq
  serviceName: smp-activemq
  replicas: 1
  template:
    metadata:
      labels:
        app: smp-activemq
    spec:
      containers:
      - name: smp-activemq
        image: dasdebde/activemq:5.15.9
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 61616
          name: smp-activemq
        volumeMounts:
        - name: www
          mountPath: <mount-path>
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "<storageclass-name>"
      resources:
        requests:
          storage: 1Gi

That what you need to define is your StorageClass name and mountPath. 您需要定义的是StorageClass名称和mountPath。 I hope it will helps you. 我希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM