How to Deploy Tomcat on k8s

来自linux中国网wiki
Evan讨论 | 贡献2022年6月28日 (二) 11:33的版本
跳到导航 跳到搜索

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





R

K8s部署tomcat mysql 与ingress暴露服务#tomcat

四、k8s部署tomcat