前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kubernetes集群部署tomcat容器/Java web应用流程

Kubernetes集群部署tomcat容器/Java web应用流程

作者头像
菲宇
发布2019-06-12 16:29:09
1.4K0
发布2019-06-12 16:29:09
举报
文章被收录于专栏:菲宇菲宇
  • kube-tomcat.yaml实现如下。

这里是把Deployment和Services在一个文件中实现了。也可以分为两个文件来实现。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

# Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Configuration to deploy release version of the Dashboard UI. # # Example usage: kubectl create -f <this_file> kind: Deployment apiVersion: extensions/v1beta1 metadata: labels: app: kube-tomcat version: v1.1.1 name: kube-tomcat namespace: default spec: replicas: 1 selector: matchLabels: app: kube-tomcat template: metadata: labels: app: kube-tomcat spec: containers: - name: kube-tomcat image: docker.io/tomcat imagePullPolicy: Always ports: - containerPort: 8080 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. - --apiserver-host=http://47.97.90.38:8080 ## 请修改为自己的kube-apiserver livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 30 timeoutSeconds: 30 --- kind: Service apiVersion: v1 metadata: labels: app: kube-tomcat name: kube-tomcat namespace: default spec: type: NodePort ports: - port: 80 targetPort: 8080 selector: app: kube-tomcat

完整的文件如下:

  • 在master上,然后使用如下命令创建deployment和Service

1

kubectl create -f kube-tomcat.yaml

查看创建的deployment:、

1

kubectl get deployment

查看这个deployment的详情:

1

kubectl describe deployment kube-tomcat

查看创建的service:

1

kubectl get service

查看这个service的详情。

1

kubectl describe service kube-tomcat

  • service详情这里的IP就是CLUSTER-IP. CLUSTER-IP是和service绑定的。
  • service详情这里的Port就是Service的端口号。
  • service详情这里的NodePort就是Node的真实端口号。
  • service详情这里的Endpoints就是容器的IP和port。

查看创建的pod:

1

kubectl get pod

查看其中一个pod的详情。

pod详情这里的IP是nodes中的虚拟IP。该虚拟IP可以去nodes里面使用ifconfig查看。

1

kubectl describe pod kube-tomcat-1115055280-tk1f8

在nodes上查看创建的容器:

这里一定要指定namespaces和services。

  • 然后到nodes中,把war使用“docker cp”复制到容器的tomcat/webapps,就可以实现页面的访问了【这里可能需要等待较多时间,至少几分钟】
  • 在Postman中进行测试

注意在请求中的IP应该是master所在的IP。返回成功。可以使用Postman来进行接口测试,测试通过表示部署成功。

  • 以上步骤的部署也可以结合持续集成CI/CD来进行,能简化不少流程。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年09月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档