原文:https://mp.weixin.qq.com/s/vFNFy3IyfpkJLUy9hISaVQ
(1)制作tomcat镜像,按如下步骤
mkdir /root/tomcat_image
把上面的war包和jar包传到这个目录下
cat Dockerfile
FROM tomcat ADD metrics.war /usr/local/tomcat/webapps/ ADD simpleclient-0.8.0.jar /usr/local/tomcat/lib/ ADD simpleclient_common-0.8.0.jar /usr/local/tomcat/lib/ ADD simpleclient_hotspot-0.8.0.jar /usr/local/tomcat/lib/ ADD simpleclient_servlet-0.8.0.jar /usr/local/tomcat/lib/ ADD tomcat_exporter_client-0.0.12.jar /usr/local/tomcat/lib/
docker build -t='xianchao/tomcat_prometheus:v1' .
docker login
username:xianchao
password:1989317**
docker push xianchao/tomcat_prometheus:v1
#上传镜像到hub仓库
docker pull xianchao/tomcat_prometheus:v1
#在k8s的node节点拉取镜像
(2)基于上面的镜像创建一个tomcat实例
cat deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: tomcat-deployment namespace: default spec: selector: matchLabels: app: tomcat replicas: 2 # tells deployment to run 2 pods matching the template template: # create pods using pod definition in this template metadata: labels: app: tomcat annotations: prometheus.io/scrape: 'true' spec: containers: - name: tomcat image: xianchao/tomcat_prometheus:v1 ports: - containerPort: 8080 securityContext: privileged: true
kubectl apply -f deploy.yaml
(3)创建一个service,可操作也可不操作
cat tomcat-service.yaml
kind: Service #service 类型 apiVersion: v1 metadata: # annotations: # prometheus.io/scrape: 'true' name: tomcat-service spec: selector: app: tomcat ports: - nodePort: 31360 port: 80 protocol: TCP targetPort: 8080 type: NodePort
kubectl apply -f tomcat-service.yaml