1. deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: tomcat-pmss
  5. namespace: test
  6. labels:
  7. app: tomcat-pmss
  8. spec:
  9. replicas: 2
  10. selector:
  11. matchLabels:
  12. app: tomcat-pmss
  13. template:
  14. metadata:
  15. labels:
  16. app: tomcat-pmss
  17. spec:
  18. containers:
  19. - name: tomcat-test1
  20. image: harbor.odl.com/public/tomcat:v1.0
  21. imagePullPolicy: IfNotPresent
  22. ports:
  23. - containerPort: 8080
  24. volumeMounts:
  25. - name: pmss
  26. mountPath: /usr/local/tomcat/webapps
  27. volumes:
  28. - name: pmss
  29. hostPath:
  30. path: /data/tomcat/pmss

2. service.yaml

apiVersion: v1
kind: Service
metadata:
  name: tomcat-pmss
  namespace: test
  labels:
    name: tomcat-pmss
spec:
  type: NodePort
  ports:
  - port: 8080 
    targetPort: 8080
    nodePort: 18080
  selector:
    app: tomcat-pmss

3. 查看资源

[root@hdss7-21 ~]# kubectl get deployment -n test
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
tomcat-pmss   2/2     2            2           29m

[root@hdss7-21 ~]# kubectl get pods -n test -o wide
NAME                           READY   STATUS    RESTARTS   AGE   IP           NODE                NOMINATED NODE   READINESS GATES
tomcat-pmss-5d56c9d75f-24clj   1/1     Running   0          26m   172.7.22.4   hdss7-22.host.com   <none>           <none>
tomcat-pmss-5d56c9d75f-zt5k8   1/1     Running   0          26m   172.7.21.2   hdss7-21.host.com   <none>           <none>

[root@hdss7-21 ~]# kubectl get svc -n test
NAME           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
tomcat-pmss    NodePort    192.168.197.58   <none>        8080:18080/TCP   3h18m