[关闭]
@zhaikun 2017-09-02T18:24:53.000000Z 字数 2801 阅读 1212

kubernetes构建一套基础tomcat8 jdk8镜像

docker


1、RC类型tomcat基础镜像

  1. #1、编写yaml文件
  2. apiVersion: v1 #api版本 固定
  3. kind: ReplicationController #kind类型ReplicationController
  4. metadata:
  5. name: zk-web
  6. spec: #spec.selector是RC的pod选择器,spec.selector是RC的pod选择器,确保当前集群上始终有且仅有replicas个pod实例运行,这里我们spec.replicas=1表示只能运行一个(名为的zk-web)pod 实例
  7. replicas: 1 #指启动几个副本
  8. selector: #pod选择器
  9. app: zk-web
  10. template: #当集群中运行的pod数量小于replicas时,RC会根据spec.template 段定义的pod模版来生成一个新的pod实例,labels属性指定了该pod的标签,这里的labels必须匹配RC的spec.selecto
  11. metadata:
  12. labels:
  13. app: zk-web
  14. spec: #spec.image表示镜像地址。
  15. containers:
  16. - name: zk-web
  17. image: harbor.suixingpay.com/study/tomcat-app:v2
  18. ports: #表示容器服务的端口
  19. - containerPort: 8080
  20. env: #表示定义环境变量
  21. - name: MYSQL_SERVICE_HOST
  22. value: 'zk-mysql'
  23. - name: MYSQL_SERVICE_PORT
  24. value: '3306'

1、TOMCAT Docerfile

  1. FROM harbor.suixingpay.com/study/centos:6.7
  2. RUN yum install wget -y
  3. RUN wget -O /etc/yum.repos.d/epel.repo http://172.16.132.241/epel/epel.repo
  4. RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://172.16.132.241/centos/CentOS-Base.repo
  5. RUN yum makecache fast
  6. RUN yum install tar wget openssl openssh-server sudo -y
  7. RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
  8. RUN echo "root:root" | chpasswd
  9. ##优化
  10. RUN echo '* - nofile 65535 ' >>/etc/security/limits.conf
  11. RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  12. # install JDK1.8
  13. RUN wget http://172.16.132.241/soft/jdk/8u111/jdk-8u111-linux-x64.tar.gz
  14. RUN tar zxvf jdk-8u111-linux-x64.tar.gz -C /opt
  15. #RUN echo 'JAVA_HOME="/opt/jdk_1.8"' >>/etc/profile
  16. #RUN echo 'CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib"'>>/etc/profile
  17. #RUN echo 'PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin"' >>/etc/profile
  18. ENV JAVA_HOME /opt/jdk1.8.0_111
  19. ADD apache-tomcat-8.0.14.tar.gz /opt
  20. RUN cd /opt/ && ls
  21. EXPOSE 22
  22. EXPOSE 8080
  23. #RUN cd /opt/ && ls &&tar zxvf /opt/apache-tomcat-8.0.14.tar.gz
  24. ENV CATALINA_HOME /opt/apache-tomcat-8.0.14
  25. ENV PATH $PATH:$CATALINA_HOME/bin
  26. ADD tomcat.sh /etc/init.d/tomcat
  27. RUN chmod +x /etc/init.d/tomcat
  28. #CMD ["/opt/tomcat.sh start"]
  29. # /sbin/service sshd start
  30. ENTRYPOINT /sbin/service sshd start && /sbin/service tomcat start && tail -f /opt/apache-tomcat-8.0.14/logs/catalina.out
  31. #EXPOSE 22
  32. #EXPOSE 8080
  33. ##tomcat.sh
  34. export JAVA_HOME=/opt/jdk1.8.0_111
  35. export TOMCAT_HOME=/opt/apache-tomcat-8.0.14
  36. case $1 in
  37. start)
  38. sh $TOMCAT_HOME/bin/startup.sh
  39. ;;
  40. stop)
  41. sh $TOMCAT_HOME/bin/shutdown.sh
  42. ;;
  43. restart)
  44. sh $TOMCAT_HOME/bin/shutdown.sh
  45. sh $TOMCAT_HOME/bin/startup.sh
  46. ;;
  47. esac
  48. exit 0
  49. ##生成镜像
  50. [root@k8s-harbor01 tomcat]# docker build -t harbor.suixingpay.com/zhaikun/cent_tomcat:3.1 .
  51. [root@k8s-harbor01 tomcat]# docker push harbor.suixingpay.com/zhaikun/cent_tomcat:3.1

2、RC类型基础镜像

  1. apiVersion: v1
  2. kind: ReplicationController
  3. metadata:
  4. name: zk-jdk-tomcat
  5. spec:
  6. replicas: 1
  7. selector:
  8. app: zk-jdk-tomcat
  9. template:
  10. metadata:
  11. labels:
  12. app: zk-jdk-tomcat
  13. spec:
  14. containers:
  15. - name: zk-jdk-tomcat
  16. image: harbor.suixingpay.com/zhaikun/cent_tomcat:3.1
  17. ports:
  18. - containerPort: 8080

1、SERVER类型基础镜像

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: zk-jdk-tomcat
  5. spec:
  6. type: NodePort
  7. ports:
  8. - port: 8080
  9. nodePort: 30009
  10. selector:
  11. app: zk-jdk-tomcat
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注