“How to Deploy Tomcat on k8s”的版本间的差异
跳到导航
跳到搜索
(创建页面,内容为“k8s部署tomcat =R= K8s部署tomcat mysql 与ingress暴露服务#tomcat [https://www.jianshu.com/p/26d25939eadf 四、k8s部署tomcat]”) |
(→R) |
||
(未显示同一用户的4个中间版本) | |||
第1行: | 第1行: | ||
− | k8s部署tomcat | + | =k8s部署tomcat= |
+ | ==Deployment== | ||
+ | <pre> | ||
+ | root@k8s-master ~]# cat tomcat.yml | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: tomcat-deployment | ||
+ | labels: | ||
+ | app: tomcat | ||
+ | spec: | ||
+ | replicas: 3 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: tomcat | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: tomcat | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: tomcat | ||
+ | image: tomcat:latest | ||
+ | ports: | ||
+ | - containerPort: 8080 | ||
+ | #run | ||
+ | [root@k8s-master ~]# kubectl apply -f tomcat.yml | ||
+ | deployment.apps/tomcat-deployment created | ||
+ | </pre> | ||
− | = | + | 具体Deployment编写细节请参考以下地址: |
+ | https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/ | ||
+ | |||
+ | == 查看 和状态== | ||
+ | <pre> | ||
+ | kubectl get deployments | ||
+ | NAME READY UP-TO-DATE AVAILABLE AGE | ||
+ | tomcat-deployment 3/3 3 3 3m29s | ||
+ | |||
+ | |||
+ | [root@k8s-master ~]# kubectl get pods -o wide | ||
+ | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES | ||
+ | |||
+ | myweb-j78ct 1/1 Running 1 45h 10.244.1.5 k8s-node1 <none> <none> | ||
+ | myweb-vhxx9 1/1 Running 1 45h 10.244.2.3 k8s-node2 <none> <none> | ||
+ | |||
+ | tomcat-deployment-84ff9bf6b4-2f5cc 1/1 Running 0 3m49s 10.244.2.5 k8s-node2 <none> <none> | ||
+ | tomcat-deployment-84ff9bf6b4-7g26m 1/1 Running 0 3m49s 10.244.0.11 k8s-master <none> <none> | ||
+ | tomcat-deployment-84ff9bf6b4-qptr7 1/1 Running 0 3m49s 10.244.1.6 k8s-node1 <none> <none> | ||
+ | [root@k8s-master ~]# curl 10.244.1.6:8080 | ||
+ | <!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | ==创建service提供外部访问== | ||
+ | <pre> | ||
+ | cat tomcat-service.yaml | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: tomcat-service | ||
+ | spec: | ||
+ | type: NodePort | ||
+ | ports: | ||
+ | - port: 8080 | ||
+ | targetPort: 8080 | ||
+ | nodePort: 30080 | ||
+ | selector: | ||
+ | app: tomcat | ||
+ | |||
+ | kubectl apply -f tomcat-service.yaml | ||
+ | |||
+ | |||
+ | # kubectl get service | ||
+ | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | ||
+ | kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d3h | ||
+ | myweb-vhxx9 NodePort 10.110.242.197 <none> 8080:31747/TCP 45h | ||
+ | nginx-pod NodePort 10.97.117.84 <none> 80:32026/TCP 2d3h | ||
+ | tomcat-service NodePort 10.97.228.221 <none> 8080:30080/TCP 10m | ||
+ | [root@k8s-master ~]# | ||
+ | |||
+ | visat mastip + 30080 | ||
+ | http://192.168.10.158:30080/ | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | <pre> | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | =Reference= | ||
[[K8s部署tomcat mysql 与ingress暴露服务#tomcat]] | [[K8s部署tomcat mysql 与ingress暴露服务#tomcat]] | ||
[https://www.jianshu.com/p/26d25939eadf 四、k8s部署tomcat] | [https://www.jianshu.com/p/26d25939eadf 四、k8s部署tomcat] | ||
+ | |||
+ | |||
+ | [[category:k8s]] |
2022年6月30日 (四) 02:11的最新版本
k8s部署tomcat
Deployment
root@k8s-master ~]# cat tomcat.yml apiVersion: apps/v1 kind: Deployment metadata: name: tomcat-deployment labels: app: tomcat spec: replicas: 3 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat:latest ports: - containerPort: 8080 #run [root@k8s-master ~]# kubectl apply -f tomcat.yml deployment.apps/tomcat-deployment created
具体Deployment编写细节请参考以下地址: https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
查看 和状态
kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE tomcat-deployment 3/3 3 3 3m29s [root@k8s-master ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES myweb-j78ct 1/1 Running 1 45h 10.244.1.5 k8s-node1 <none> <none> myweb-vhxx9 1/1 Running 1 45h 10.244.2.3 k8s-node2 <none> <none> tomcat-deployment-84ff9bf6b4-2f5cc 1/1 Running 0 3m49s 10.244.2.5 k8s-node2 <none> <none> tomcat-deployment-84ff9bf6b4-7g26m 1/1 Running 0 3m49s 10.244.0.11 k8s-master <none> <none> tomcat-deployment-84ff9bf6b4-qptr7 1/1 Running 0 3m49s 10.244.1.6 k8s-node1 <none> <none> [root@k8s-master ~]# curl 10.244.1.6:8080 <!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is
创建service提供外部访问
cat tomcat-service.yaml apiVersion: v1 kind: Service metadata: name: tomcat-service spec: type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 30080 selector: app: tomcat kubectl apply -f tomcat-service.yaml # kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d3h myweb-vhxx9 NodePort 10.110.242.197 <none> 8080:31747/TCP 45h nginx-pod NodePort 10.97.117.84 <none> 80:32026/TCP 2d3h tomcat-service NodePort 10.97.228.221 <none> 8080:30080/TCP 10m [root@k8s-master ~]# visat mastip + 30080 http://192.168.10.158:30080/