kubernetes运行tomcat

一 工作目录

root@k8s-master-01:/data/k8s/yaml/tomcat# pwd
/data/k8s/yaml/tomcat

二 编写tomcat-app.yaml

查看代码
root@k8s-master-01:/data/k8s/yaml/tomcat# cat tomcat-app1.yaml 
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: wgs-tomcat-app1-deployment-label
  name: wgs-tomcat-app1-deployment
  namespace: wgs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wgs-tomcat-app1-selector
  template:
    metadata:
      labels:
        app: wgs-tomcat-app1-selector
    spec:
      containers:
      - name: wgs-tomcat-app1-container
        image: 192.168.174.120/baseimages/tomcat-app1:v1.0
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          protocol: TCP
          name: http
        env:
        - name: "tomcat-version"
          value: "8.5.0"
        resources:
          limits:
            cpu: 1
            memory: "512Mi"
          requests:
            cpu: 500m
            memory: "512Mi"
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: wgs-tomcat-app1-service-label
  name: wgs-tomcat-app1-service
  namespace: wgs
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
    nodePort: 40003
  selector:
    app: wgs-tomcat-app1-selector

三 创建tomcat pod

root@k8s-master-01:/data/k8s/yaml/tomcat# kubectl apply -f tomcat-app1.yaml 
deployment.apps/wgs-tomcat-app1-deployment created
service/wgs-tomcat-app1-service created

四 查看tomcat pod

root@k8s-master-01:/data/k8s/yaml/tomcat# kubectl get pods -n wgs -o wide
NAME                                          READY   STATUS    RESTARTS   AGE   IP              NODE              NOMINATED NODE   READINESS GATES
wgs-tomcat-app1-deployment-764458b74f-xbd7r   1/1     Running   0          50s   10.200.89.143   192.168.174.108   <none>           <none>

五 查看tomcat svc

root@k8s-master-01:/data/k8s/yaml/tomcat# kubectl get svc -n wgs -o wide
NAME                      TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR
wgs-tomcat-app1-service   NodePort   10.100.39.62   <none>        80:40003/TCP   73s   app=wgs-tomcat-app1-selector

六 查看当前deloyment

root@k8s-master-01:/data/k8s/yaml/tomcat# kubectl get deployment -n wgs
NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
wgs-tomcat-app1-deployment   1/1     1            1           7m35s

七 访问tomcat

kubernetes运行tomcat

 

上一篇:kubernetes运行nginx+tomcat


下一篇:map组件如何展示marker的callout气泡