制作docker镜像
下载jdk,tomcat
apache-tomcat-8.5.77.tar.gz jdk-8u311-linux-x64.tar.gz
将jdk,tomcat,war包导入虚拟机
编写Doukerfile
FROM centos:7
MAINTAINER xxxx@qq.com
ADD ./jdk-8u311-linux-x64.tar.gz /usr/local/
ADD ./apache-tomcat-8.5.77.tar.gz /usr/local/
ADD ./k8s-demo.war /usr/local/apache-tomcat-8.5.77/webapps/
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_311
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.77
ENV CATALINA_BASH /usr/local/apache-tomcat-8.5.77
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
ENTRYPOINT ["/usr/local/apache-tomcat-8.5.77/bin/catalina.sh","run"]
另一种写法通过第三方镜像的方式
FROM tomcat:8.5
MAINTAINER XXX@q1.com
ADD ./k8s-demo.war /usr/local/tomcat/webapps/
EXPOSE 8080
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
生成镜像
cd /usr/local/test
docker build -f tomcat8.5.Dockerfile -t k8s-tomcat .
docker images
将镜像上传到本地私有镜像仓库
docker tag k8s-tomcat 192.168.99.192:5000/k8s-tomcat:v1.0
docker rmi k8s-tomcat
docker push 192.168.99.192:5000/k8s-tomcat:v1.0
编写k8s yaml文件
vi k8s-tomcat.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-tomcat
namespace: wl-namespace
spec:
selector:
matchLabels:
app: k8s-tomcat
replicas: 1
template:
metadata:
labels:
app: k8s-tomcat
spec:
containers:
- name: k8s-tomcat
image: 192.168.99.192:5000/k8s-tomcat:v1.0
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: k8s-tomcat
namespace: wl-namespace
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: k8s-tomcat
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: k8s-tomcat
namespace: wl-namespace
spec:
rules:
- host: www.k8s.demo
http:
paths:
- path: /
backend:
serviceName: k8s-tomcat
servicePort: 80
运行pod
kubectl apply -f k8s-tomcat.yaml
kubectl get All -n wl-namespace
|