第三节:通过k8s部署django

jenkins通过k8s部署django

一、部署mysql

1、部署命名空间

apiVersion: v1
kind: Namespace
metadata:
  name: mysql

2、部署service

kind: Service
apiVersion: v1
metadata:
  name: mysql-svc
  namespace: mysql
spec:
  ports:
    - port: 3306
      targetPort: 3306
      name: mysql
      protocol: TCP
  selector:
    app: mysql
    deploy: django

3、部署PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-mysql-pvc
  namespace: mysql
spec:
  storageClassName: nfs-client
  accessModes:
    - "ReadWriteMany"
  resources:
    requests:
      storage: "20Gi"

4、部署Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
  namespace: mysql
spec:
  selector:
    matchLabels:
      app: mysql
      deploy: django
  template:
    metadata:
      labels:
        app: mysql
        deploy: django
    spec:
      nodeName: k8s-node-02
      containers:
        - name: mysql
          image: mysql:5.7
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "123456"
            - name: MYSQL_DATABASE
              value: "django"
            - name: MYSQL_USER
              value: djg
            - name: MYSQL_PASSWORD
              value: "123456"
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: mysql-data
      volumes:
        - name: mysql-data
          persistentVolumeClaim:
            claimName: pv-mysql-pvc

二、准备django镜像

1、编写dockerfile镜像

[root@docker01 ~/k8s_Django/image]# cat Dockerfile 
FROM python:3.6.13

WORKDIR /opt

# 安装Django依赖
ADD requirement.txt /opt
RUN pip install -r requirement.txt

ADD transfer.sh /opt

CMD ["/bin/sh","-c","/opt/transfer.sh"]

2、编写部署依赖清单

联系管理员微信tutu19192010,注册账号

上一篇
下一篇
Copyright © 2022 Egon的技术星球 egonlin.com 版权所有 青浦区尚茂路798弄 联系方式-13697081366