Kubernetes POD创建问题mysql PV,PVC问题,centos 7.3.1611

时间:2017-05-26 11:11:24

标签: mysql kubernetes

希望你做得好。 我在同一个VM中有Kubernetes Master和slave模拟==> centos 7.3.1611,2gb ram,2个虚拟核心。

Mysql容器服务。

用户已登录:root

Kubernetes版本:1.5

        Temp directory
        --------------
        mkdir -p /tmp/work/data /tmp/work/init

        db.sql

        create table `item`(`id` bigint not null auto_increment primary key, `description` varchar(100), `done` bit);
        insert into `item`(`id`,`description`, `done`) valumes(1, 'Today is Friday', 0);
        insert into `item`(`id`,`description`, `done`) valumes(2, 'Today is Saturday', 1);

        cp db.sql /tmp/work/init


        pv001.yaml

        apiVersion: v1
        kind: PersistentVolume
        metadata:
          name: pv001
          labels:
            type: local
        spec:
          capacity:
            storage: 1Gi
          accessModes:
            - ReadWriteOnce
          #persistentVolumeReclaimPolicy: Recycle
          hostPath:
            path: "/tmp/work/data"

        pv002.yaml

        apiVersion: v1
        kind: PersistentVolume
        metadata:
          name: pv002
          labels:
            type: local
        spec:
          capacity:
            storage: 1Mi
          accessModes:
            - ReadWriteOnce
          #persistentVolumeReclaimPolicy: Recycle
          hostPath:
            path: "/tmp/work/init"


        dbclaim.yaml

        apiVersion: v1
        kind: PersistentVolumeClaim
        metadata:
          name: dbclaim
          labels:
            name: map_data_volume
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 1Gi

        dbinit.yaml

        apiVersion: v1
        kind: PersistentVolumeClaim
        metadata:
          name: dbinit
          labels:
            name: map_init_volume
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 1Mi


        mkdir -p /var/lib/mysql/data /var/lib/mysql/init

        mysql-pvc-pod.yaml

        apiVersion: v1
        kind: Pod
        metadata:
          name: mysql-pvc-pod
          labels:
            name: mysql-pvc-pod
        spec:
          containers:
            - resources:
                limits :
                  cpu: 1
              image: mysql
              name: mysql-pvc-pod
              env:
                - name: MYSQL_ROOT_PASSWORD
                  # change this
                  value: welcome1
                - name: MYSQL_USER
                  value: testuser
                - name: MYSQL_PASSWORD
                  value: mypass123
              ports:
                - containerPort: 3310
                  name: mysql-pvc-pod
              volumeMounts:
               - mountPath: /var/lib/mysql/data
                 name: db-volume
               - mountPath: /var/lib/mysql/init
                 name: db-init
          volumes:
            - name: db-volume
              persistentVolumeClaim:
                claimName: dbclaim
            - name: db-init
              persistentVolumeClaim:
                claimName: dbinit

        mysql-pvc-pod-service.yaml

        apiVersion: v1
        kind: Service
        metadata:
          labels:
            name: mysql-pvc-service
          name: mysql-pvc-service
        spec:
          externalIPs:
            - 10.0.2.15
          ports:
            # the port that this service should serve on
            - port: 3310
          # label keys and values that must match in order to receive traffic for this service
          selector:
            name: mysql-pvc-service

错误

我的POD崩溃了:CrashLoopBackOff

[root @ centos7~] #kubectl get pods

NAME READY STATUS RESTARTS AGE

mysql-pvc-pod 0/1 CrashLoopBackOff 8 18m

1 个答案:

答案 0 :(得分:0)

尝试使用粘滞位设置授予全局写入权限。然后重新创建pod

chmod 1777 /tmp/work/data /tmp/work/init

感谢 -SR