【云计算赛项】职业技能竞赛--容器开发部分例题K8s编排部署WebMall

基于Kubernetes 编排部署GPmall

  • 前言
    • 目标
    • 基础准备
    • 1.Redis 容器化部署
      • 编写 yum 文件
      • 编写 Dockerfile 文件
      • 构建镜像
      • 查看镜像列表
    • 2.Mariadb 容器化部署
      • 编写 Dockerfile
    • 3.ZooKeeper 容器化部署
      • 编写 Dockerfile
    • 4.编排部署 GPMall
      • 编写gpmall.yaml
    • 5.访问测试

前言

在这里插入图片描述

在这里插入图片描述

目标

用k8s编码容器,部署一个商城

基础准备

Kubernetes 集群已部署完成,将提供的压缩包 GPMall.tar.gz 上传到 master 节点/root 目录下并解压

1.Redis 容器化部署

编写 yum 文件

[root@master ~]# cd gpmall/
[root@master gpmall]# cat local.repo
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall
gpgcheck=0
enabled=1

编写 Dockerfile 文件

[root@master gpmall]# cat Dockerfile-redis
FROM centos:centos7.5.1804
MAINTAINER Pyy
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
RUN yum -y install redis
EXPOSE 6379
RUN yum clean all
RUN sed -i -e 's@bind 127.0.0.1@bind 0.0.0.0@g' /etc/redis.conf
RUN sed -i -e 's@protected-mode yes@protected-mode no@g' /etc/redis.conf
ENTRYPOINT [ "/usr/bin/redis-server","/etc/redis.conf"]

构建镜像

构建镜像 gpmall-redis:v1.0:

[root@master gpmall]# docker build -t gpmall-redis:v1.0 -f Dockerfile-redis .

查看镜像列表

[root@master gpmall]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gpmall-redis v1.0 7e662e15d3e4 1 minutes ago 464MB

2.Mariadb 容器化部署

编写 Dockerfile

# cat Dockerfile-mariadb
FROM centos:centos7.5.1804
MAINTAINER pyy
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
RUN yum install -y MariaDB-server expect net-tools
RUN yum clean all
COPY gpmall.sql /opt/
ADD mysql_init.sh /opt/
RUN chmod +x /opt/mysql_init.sh
RUN /opt/mysql_init.sh
ENV LC_ALL en_US.UTF-8
EXPOSE 3306
CMD ["mysqld_safe]

3.ZooKeeper 容器化部署

编写 Dockerfile

root@master gpmall]# cat Dockerfile-zookeeper
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
RUN yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
ENV work_path /usr/local
WORKDIR $work_path
ADD zookeeper-3.4.14.tar.gz /usr/local
ENV ZOOKEEPER_HOME /usr/local/zookeeper-3.4.14
ENV PATH $PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin
RUN cp $ZOOKEEPER_HOME/conf/zoo_sample.cfg $ZOOKEEPER_HOME/conf/zoo.cfg
EXPOSE 2181

4.编排部署 GPMall

编写gpmall.yaml

root@master gpmall]# cat gpmall.yaml
apiVersion: v1
kind: Pod
metadata:
name: chinaskill-mall
labels:
app: chinaskill-mall
spec:
containers: - name: chinaskill-mariadb
image: 192.168.100.10/library/gpmall-mariadb:v1.0
imagePullPolicy: IfNotPresent
ports: - containerPort: 3306
- name: chinaskill-redis
image: 192.168.100.10/library/gpmall-redis:v1.0
imagePullPolicy: IfNotPresent
ports: - containerPort: 6379
19
- name: chinaskill-zookeeper
image: 192.168.100.10/library/gpmall-zookeeper:v1.0
imagePullPolicy: IfNotPresent
ports: - containerPort: 2181
...

5.访问测试

你可能感兴趣的:(云计算,docker,kubernetes)