单个ActiveMQ部署就像部署Java应用,首先依赖docker制作Dockerfile,这要确保docker镜像build和run成功,放到仓库,需要注意ActiveMQ的jetty.xml配置。
然后手动编写kubernetes文件:activemq-deployment.yml 和 activemq-service.yml。通过NodePort模式对外暴露端口。
[root@master1 ~]# ls
activemq-deployment.yml activemq-service.yml apache-activemq-5.16.0-bin.tar.gz
dockerfile_activemq jdk-8u251-linux-x64.tar.gz
dockerfile_activemq
[root@master1 ~]# cat dockerfile_activemq
FROM centos:latest
MAINTAINER lyd
ADD jdk-8u251-linux-x64.tar.gz /usr/local/
ADD apache-activemq-5.16.0-bin.tar.gz /usr/local/
RUN cd /usr/local && ls && mv apache-activemq-5.16.0 activemq
ENV JAVA_HOME=/usr/local/jdk1.8.0_251
ENV CLASSPATH=.$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH
EXPOSE 61616 8161
ENTRYPOINT /usr/local/activemq/bin/activemq start && /bin/bash
# docker build -f dockerfile_activemq -t activemq .
# mq使用的端口较多,启动时主要是端口映射
# AMQ使用默认61616提供JMS服务,8161提供web管控台服务。
# docker run -dit --name activemq -p 61616:61616 -p 8161:8161 activemq
# docker run -dit --name activemq -p 61616:61616 -p 8161:8161 -p 30081:8161 -p 30061:61616 activemq
# netstat -nltp|grep -E '(61616|8161)' 查看映射端口
[root@master ~]# docker build -f dockerfile_activemq -t activemq:latest .
登录docker hub,修改activemq 的 tag入到仓库lyndon1107/activemq。
[root@master1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lyndon1107/activemq latest 9a0ea80df4a7 2 hours ago 760MB
activemq latest 9a0ea80df4a7 2 hours ago 760MB
k8s.gcr.io/kube-proxy v1.18.16 f64b8b5e96a6 4 weeks ago 117MB
k8s.gcr.io/kube-controller-manager v1.18.16 b3c57ca578fb 4 weeks ago 162MB
k8s.gcr.io/kube-apiserver v1.18.16 26e38f7f559a 4 weeks ago 173MB
k8s.gcr.io/kube-scheduler v1.18.16 5a84bb672db8 4 weeks ago 96.1MB
quay.io/coreos/flannel v0.13.1-rc2 dee1cac4dd20 7 weeks ago 64.3MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 13 months ago 683kB
k8s.gcr.io/coredns 1.6.7 67da37a9a360 13 months ago 43.8MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 17 months ago 288MB
简介:Deployment是k8s用来管理部署无状态Pod的控制器。
适用场景:无状态应用,所有的pod无依赖关系,无指定节点运行、无特殊处理的方式部署。
Deployment并不是直接管理Pod,而是通过ReplicaSet对象间接管理的,也就是说真正管理pod的其实是replicaSet对象。
通过kubectl describe查看deploment的详情,可以看到NewReplicaSet的值指向的是ReplicaSet对象,并间接管理Pod。
activemq-deployment.yml
[root@master1 ~]# cat activemq-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: activemq-deployment
labels: #标签key-value键值对
app: activemq
spec:
replicas: 1
selector:
matchLabels:
app: activemq
template:
metadata:
labels:
app: activemq
spec:
containers:
- name: activemq
image: lyndon1107/activemq:latest
imagePullPolicy: IfNotPresent
command: ["/bin/bash", "-ce", "tail -f /dev/null" ]
ports:
- containerPort: 61616 #容器对外开放端口,暴露给Service的地址
- containerPort: 8161
nodeName: node2 #指定节点运行
即k8s的Service定义了一个服务的访问入口地址,前端的应用通过这个入口地址访问其背后的一组由Pod副本组成的集群实例,来自外部的访问请求被负载均衡到后端的各个容器应用上。
activemq-service.yml 通过NodePort模式对外暴露了61616和8161端口。
[root@master1 ~]# cat activemq-service.yml
apiVersion: v1
kind: Service
metadata:
name: activemq-service #名称
labels:
app: activemq
spec:
type: NodePort #通信方式采用节点端口类型
ports:
- name: admin
port: 8161 #service暴露在cluster ip上的端口
targetPort: 8161 #pod上的端口
nodePort: 30081 #Service对外开放端口
- name: tcp
port: 61616
targetPort: 61616
protocol: TCP
nodePort: 30061
selector:
app: activemq #容器的标签
[root@master1 ~]# kubectl apply -f activemq-deployment.yml
deployment.apps/activemq-deployment created
[root@master1 ~]# kubectl apply -f activemq-service.yml
service/activemq-service created
[root@master1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
activemq-deployment-5fb4cccb97-2zmxh 1/1 Running 0 9m6s
READY 1
[root@master1 ~]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/activemq-deployment-5fb4cccb97-2zmxh 1/1 Running 0 33m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/activemq-service NodePort 10.101.93.214 8161:30081/TCP,61616:30061/TCP 33m
service/kubernetes ClusterIP 10.96.0.1 443/TCP 7h11m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/activemq-deployment 1/1 1 1 33m
NAME DESIRED CURRENT READY AGE
replicaset.apps/activemq-deployment-5fb4cccb97 1 1 1 33m
[root@node2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lyndon1107/activemq latest 9a0ea80df4a7 6 hours ago 760MB
k8s.gcr.io/kube-proxy v1.18.16 f64b8b5e96a6 4 weeks ago 117MB
k8s.gcr.io/kube-apiserver v1.18.16 26e38f7f559a 4 weeks ago 173MB
k8s.gcr.io/kube-controller-manager v1.18.16 b3c57ca578fb 4 weeks ago 162MB
k8s.gcr.io/kube-scheduler v1.18.16 5a84bb672db8 4 weeks ago 96.1MB
quay.io/coreos/flannel v0.13.1-rc2 dee1cac4dd20 7 weeks ago 64.3MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 13 months ago 683kB
k8s.gcr.io/coredns 1.6.7 67da37a9a360 13 months ago 43.8MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 17 months ago 288MB
[root@node2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25d443ded154 9a0ea80df4a7 "/bin/bash -ce 'tail…" 3 hours ago Up 3 hours k8s_activemq_activemq-deployment-5fb4cccb97-2zmxh_default_5a618886-82da-42a1-baa0-a72e044e5e99_0
24ccf5de7ac6 k8s.gcr.io/pause:3.2 "/pause" 3 hours ago Up 3 hours k8s_POD_activemq-deployment-5fb4cccb97-2zmxh_default_5a618886-82da-42a1-baa0-a72e044e5e99_0
aceff7459fbb dee1cac4dd20 "/opt/bin/flanneld -…" 9 hours ago Up 9 hours k8s_kube-flannel_kube-flannel-ds-kcwjv_kube-system_602962d2-3a97-4b5e-8ca5-5d3001c7ff62_0
11ce47afaedd k8s.gcr.io/pause:3.2 "/pause" 9 hours ago Up 9 hours k8s_POD_kube-flannel-ds-kcwjv_kube-system_602962d2-3a97-4b5e-8ca5-5d3001c7ff62_0
9eeef13fd2c0 f64b8b5e96a6 "/usr/local/bin/kube…" 10 hours ago Up 10 hours k8s_kube-proxy_kube-proxy-8f7zr_kube-system_0a0d2ad1-3a6a-4a7a-930a-0887391d3389_1
23b9bae030ef k8s.gcr.io/pause:3.2 "/pause" 10 hours ago Up 10 hours k8s_POD_kube-proxy-8f7zr_kube-system_0a0d2ad1-3a6a-4a7a-930a-0887391d3389_1
用户service暴露的端口30081访问地址 http://192.168.11.8:30081/admin 输入用户名密码 admin admin
完
deployment中镜像位置,追加指令command
command: [“/bin/bash”, “-ce”, “tail -f /dev/null” ] 这样导致结果actvemq可能应用程序未启动起来。启动了空服务。
这个如果应用程序未启动,登录进docker中查看日志,执行./bin/activemq start,可以作为调试。
最简单办法就是在Dockerfile中追加空文件 java -jar xxx.jar && tail -f test 文件
CrashLoopBackOff的含义是,Kubernetes试图启动该Pod,但是过程中出现错误,导致容器启动失败或者正在被删除。
[root@master1 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
activemq-deployment-5fb4cccb97-2zmxh 1/1 Running 0 16h 10.244.3.8 node2
connect-deployment-74d6746f47-hv7sv 0/1 CrashLoopBackOff 5 6m 10.244.3.17 node2
pod报错"Back-off restarting failed container"解决办法
链接地址:https://blog.csdn.net/sqhren626232/article/details/101013390
解决方法:在deployment申明镜像的后面加上命令
command: [ “/bin/bash”, “-ce”, “tail -f /dev/null” ]
k8s之deployment详解
https://www.cnblogs.com/younger5/p/15033157.html