K8S部署:Dockerfile构建rabbitmq镜像,并部署到K8S集群暴露端口出来。
Dockerfile构建rabbitmq镜像,并部署到K8S集群暴露端口出来。一、构建rabbitmq2.8.7版本镜像背景描述:rabbitmq 版本:RabbitMQ 2.8.7erlang版本:otp_src_R16B03并已事先下载好文件到本地dockerfile文件如下:FROM centos:centos7.4.1708MAINTAINER xiaojun "490089459@qq.
·
Dockerfile构建rabbitmq镜像,并部署到K8S集群暴露端口出来。
一、构建rabbitmq2.8.7版本镜像
背景描述:
rabbitmq 版本:RabbitMQ 2.8.7
erlang版本:otp_src_R16B03
并已事先下载好文件到本地
dockerfile文件如下:
FROM centos:centos7.4.1708
MAINTAINER xiaojun "490089459@qq.com"
RUN yum install -y gcc glibc-devel gcc-c++kernel-develm4 make ncurses-devel openssl-devel xmlto perl wget xz lsof && rpm --rebuilddb
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
ADD otp_src_R16B03 /usr/local/src/otp_src_R16B03
WORKDIR /usr/local/src/otp_src_R16B03
RUN ./configure --prefix=/usr/local/erlang && make && make install
ENV ERL_HOME /usr/local/erlang
ENV PATH $PATH:$ERL_HOME/bin
ADD rabbitmq_server-2.8.7 /usr/local/rabbitmq
WORKDIR /usr/local/rabbitmq
ENV RABBITMQ_HOME /usr/local/rabbitmq
ENV PATH $PATH:$RABBITMQ_HOME/sbin
EXPOSE 5672
EXPOSE 55672
ENTRYPOINT rabbitmq-plugins enable rabbitmq_management && rabbitmq-server
CMD ["rabbitmq-server"]
构建镜像:
docker build -t rabbitmq .
将镜像提交到harbor!
二、K8S部署rabbitmq 单节点
背景描述:
K8S 使用三台服务器组建的新集群
后端存储使用cephfs
[root@k8s01 rabbitmq]# cat rabbitmq2.8.yaml
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: rabbitmq
spec:
serviceName: "rabbitmq-service"
replicas: 1
template:
metadata:
labels:
app: rabbitmq
spec:
terminationGracePeriodSeconds: 10
containers:
- name: rabbitmq
image: harbor.creditgogogo.com/ops/centos7.5-erlang-rabbitmq2.8
ports:
- containerPort: 5672
name: rabbitmqtcp
- containerPort: 55672
name: managent
volumeMounts:
- name: rabbitmqdata
mountPath: /usr/local/rabbitmq/var
volumeClaimTemplates:
- metadata:
name: rabbitmqdata
annotations:
volume.beta.kubernetes.io/storage-class: cephfs
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: rabbitmq-service
spec:
type: NodePort
ports:
- name: rabbitmqtcp
port: 5672
targetPort: 5672
nodePort: 30001
- name: managent
port: 55672
targetPort: 55672
nodePort: 30002
selector:
app: rabbitmq
[root@k8s01 rabbitmq]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rabbitmq-0 1/1 Running 0 44m 172.30.73.78 k8s01 <none> <none>
[root@k8s01 rabbitmq]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 13d
rabbitmq-service NodePort 10.254.218.239 <none> 5672:30001/TCP,55672:30002/TCP 17h
最终实现rabbitmq服务
参考连接:https://blog.csdn.net/CHENYUFENG1991/article/details/78766025
更多推荐
已为社区贡献11条内容
所有评论(0)