创建namespace
tomcat-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: ns-tomcat
创建Deployment
tomcat-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
namespace: ns-tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/tomcat:8.5-jdk8
ports:
- name: http
containerPort: 8080
创建Service
tomcat-service.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat-service
namespace: ns-tomcat
spec:
selector:
app: tomcat
ports:
- name: http
targetPort: 8080
port: 8080
nodePort: 30080
type: NodePort
启动
kubectl apply -f tomcat-namespace.yaml
kubectl apply -f .
查看
kubectl get pod -n ns-tomcat
kubectl get svc -n ns-tomcat
进入容器
kubectl exec -it tomcat-deployment-7f56bbf454-5wf7h -n ns-tomcat -- /bin/sh
tomcat-deployment-7f56bbf454-5wf7h
pod的名称
复制目录
cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
访问
http://10.0.2.12:30080/
10.0.2.12
为宿主机ip,30080
为tomcat Service的port。