1.镜像准备
docker pull tomcat
2.准备html项目
<!DOCTYPE html">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassssssssssssss
</body>
</html>
3.挂载目录
mkdir -p /srv/tomcat/w
4.给目录赋权限
chmod -R 777 /srv/tomcat
5.创建yml文件
1)vi tomcat-test-rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 1
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- image: docker.io/tomcat
name: myweb
resources:
limits:
cpu: "1"
memory: 200Mi
ports:
- containerPort: 8080
volumeMounts:
- name: httpd-storage
mountPath: /usr/local/tomcat/webapps/w
volumes:
- name: httpd-storage
hostPath:
path: /srv/tomcat/w
2)vi tomcat-test-svc.yml
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 8080
nodePort: 31087
selector:
app: myweb
3) 注 格式比较严格
6.执行yml文件
kubectl create -f tomcat-test-rc.yml
kubectl create -f tomcat-test-svc.yml
7.如果访问到 http://192.168.0.46:31087/w/ 有输出则表示成功,否则kubectl get event,kubectl get pod,describe pod查看错误信息来定位。
8.如需要yml文件或者项目和我联系,如有不对之处请指出多谢。