k8s安装常用软件的yaml文件

参考网址:https://www.bejson.com (网站文件部分有坑,需要擦亮眼睛)

nginx

k8s版本:v1.20

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-nginx
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
        - name: my-nginx
          image: nginx
          ports:
            - containerPort: 80
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              cpu: 400m
              memory: 600Mi
            limits:
              cpu: 800m
              memory: 800Mi
      volumes:
        - name: myemptydir
          emptyDir: {}

MySQL

MySQL版本:8.0.23,k8s版本:v1.20

# cat PersistentVolumeClaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-mysql-data
  namespace: test
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  storageClassName: storage # 需要事先创建好存储类
# cat service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my-mysql # 名称要跟Deployment.yaml中的保持一致
  namespace: test
spec:
  type: NodePort
  selector:
    app: my-mysql
  ports:
    - port: 3306
      targetPort: 3306
      nodePort: 32306
# cat Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-mysql
  namespace: test
  labels:
    app: my-mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-mysql
  template:
    metadata:
      labels:
        app: my-mysql
    spec:
      volumes:
        - name: my-mysql-data
          persistentVolumeClaim:
            claimName: my-mysql-data
        - name: mysql-conf
          configMap:
            name: mysql-conf
      containers:
        - env:
            - name: MYSQL_ROOT_PASSWORD #root用户密码
              value: root
            - name: MYSQL_USER # 普通用户
              value: test
            - name: MYSQL_PASSWORD # 普通用户密码
              value: test
          image: 'mysql:8.0.23'
          imagePullPolicy: IfNotPresent
          name: my-mysql
          ports:
            - containerPort: 3306
              protocol: TCP
              name: http
          volumeMounts:
            - name: my-mysql-data
              mountPath: /var/lib/mysql
            - name: mysql-conf
              mountPath: /etc/mysql/mysql.conf.d
          resources:
            requests:
              cpu: 400m
              memory: 600Mi
            limits:
              cpu: 800m
              memory: 800Mi
# cat ConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-conf
  namespace: test
data:
  mysql.cnf: |
    [mysqld]

     pid-file        = /var/run/mysqld/mysqld.pid
     socket          = /var/run/mysqld/mysqld.sock
     datadir         = /var/lib/mysql
     
     symbolic-links=0
     sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

未完待续。。。

posted @ 2021-04-25 18:34  哈喽哈喽111111  阅读(295)  评论(0编辑  收藏  举报