中间件上云流程

下载基础镜像

docker pull nginx

image-20211230105338655

查看镜像

docker images

image-20211230105434789

打包镜像

# -o 或 > 指定输出镜像文件的包名nginx.tar  nginx  镜像名
docker save -o nginx.tar nginx  
   或    
docker save > nginx.tar nginx  

image-20211230110106393

上传云服务器(略)

解压镜像

docker load < nginx.tar
    或
docker load -i nginx.tar

解压完成后会在docker images 下生成一个对应的nginx镜像

上传云服务器镜像空间

登陆对应的hub空间

docker login xxxxx   # xxxxx 代表镜像仓库的地址

上传解压好的镜像

docker push xxxxx/nginx:v1

创建一个nginx目录

mkdir nginx

打包需要的文件

image-20211230112155799

编写dockerfile文件

vi Dockerfile
FROM xxxx/nginx:v1
MAINTAINER lisongyu <li.songyu@qq.com>
USER root
WORKDIR /etc/nginx/conf.d/
EXPOSE 80
ADD ./nies-ui/ /usr/share/nginx/html/nies-ui/
ADD nies.conf /etc/nginx/conf.d/
ADD ./key ./key

编写生成上传镜像脚本

vi docker.sh
docker build -t xxxxx/nginx:1234 . # “.” 记得不要丢
docker push xxxxx/nginx:1234

给docker.sh附权并上传到镜像仓库

chmod +x docker.sh; ./docker.sh

由于我在本地,不需要上传到hub,所以我这边用nginx:1234来代替实际的远程仓库xxxxx/nginx:1234

image-20211230121605278

yaml配置文件编写

vi nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: default
  labels:
    app-name: nginx
spec:
  replicas: 1 # 设置启动的节点数
  selector:
    matchLabels:
      app-name: nginx
  template:
    metadata:
      labels:
        app-name: nginx
    spec:
      nodeSelector:
      securityContext:
        fsGroup: 1000 
        runAsUser: 0
      containers:
      - name: nginx
        image: xxxx/nginx:1234
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80  # 容器内部端口
          name: web
          protocol: TCP

---

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: default
  labels:
    app-name: nginx
  annotations:
    prometheus.io/scrape: 'true'

spec:
  selector:
    app-name: nginx
  ports:
  - name: nginx
    port: 80  # 容器内部端口
    targetPort: 80  # 容器内部端口
    nodePort: 30210  # nodePort k8s默认规定30000以上,节点机上默认访问的端口
  type: NodePort

启动容器

kubectl replace --force -f nginx.yaml

查看容器是否启动成功

kubectl get pods -n default

image-20211230121759837

查看日志并访问

kubectl logs -f nginx-6fddf6d666-fm5mc

image-20211230121928373

image-20211230122055051

posted @ 2021-12-30 12:24  lisongyu  阅读(150)  评论(0编辑  收藏  举报