zoukankan      html  css  js  c++  java
  • Kubernetes Yaml

    部署一个简单的Nginx服务:

    deployment-yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-web
    spec:
      replicas: 3
      selector:
        matchLabels:
          name: nginx-web
        template:
          metadata:
            labels:
              name: nginx-web
          spec:
            containers:
            - name: nginx-web
              image: nginx
    View Code

    service-yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: niginx-service
    spec:
      selector:
        name: nginx-web
      type: NodePort
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
        name: http
        nodePort: 30080
    View Code

    部署一个基于NFS持久化的Mysql服务:

    ---
    # mysql-pv
    
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: mysql-pv
    spec:
      accessModes:
        - ReadWriteMany
      capacity:
        storage: 1Gi
      persistentVolumeReclaimPolicy: Retain
      storageClassName: nfs
      nfs:
        path: /nfs-data/mysql-pv
        server: 172.16.65.200
    
    ---
    # mysql-pvc
    
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: mysql-pvc
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 1Gi
      storageClassName: nfs
    
    ---
    # mysql deployment
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mysql
    spec:
      selector:
        matchLabels:
          name: mysql
      template:
        metadata:
          labels:
            name: mysql
        spec:
          containers:
          - image: mysql
            name: mysql
            env:
            - name: MYSQL_ROOT_PASSWORD
              value: password
            ports:
            - containerPort: 3306
              name: mysql
            volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
          volumes:
          - name: mysql-persistent-storage
            persistentVolumeClaim:
              claimName: mysql-pvc
    
    ---
    # mysql-service
    
    apiVersion: v1
    kind: Service
    metadata:
      name: mysql
    spec:
      ports:
      - port: 3306
      selector:
       name: mysql
    View Code

    持久化测试:

    # 运行一个mysql 客户端,通过DNS服务连接到 mysql service
    # kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
    
    mysql> use mysql;
    mysql> create table my_user(name char(10));
    mysql> insert my_user values("alex");
    mysql> select * from my_user;
    +------+
    | name |
    +------+
    | alex |
    +------+
    1 row in set (0.00 sec)
     
    View Code
  • 相关阅读:
    错位排序
    不容易系列之(4)——考新郎
    大数乘法
    神、上帝以及老天爷(错位排序)
    学生成绩……
    蛇形矩阵
    topcoder
    进制转换
    问题 1011
    topcoder 针对C程序员的TopCoder C++ (快速掌握)_ixigua—仅有杀毒软件是不够的…… .
  • 原文地址:https://www.cnblogs.com/vincenshen/p/9538324.html
Copyright © 2011-2022 走看看