0
votes

Hope you are doing good. I have Kubernetes Master and slave simulation in the same VM ==> centos 7.3.1611, 2gb ram, 2 Virtual cores.

Mysql container service.

User logged in : root

Kubernetes Version : 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

ERROR

My POD crashed: CrashLoopBackOff

[root@centos7 ~]# kubectl get pods

NAME READY STATUS RESTARTS AGE

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

1
did you try to check the logs using kubectl logs -f mysql-pvc-pod?David Steiman
I have tried but no luck, i gave all the write permissions [root@centos7 ~]# ls -ltrh /var/lib/mysql/ total 0 drwxrwxrwx. 2 root root 6 May 26 05:49 data drwxrwxrwx. 2 root root 20 May 26 07:01 init [root@centos7 ~]# ls -ltrh /tmp/work/ total 0 drwxrwxrwx. 2 root root 6 May 25 19:06 data drwxrwxrwx. 2 root root 20 May 25 19:07 init [root@centos7 ~]# kubectl logs -f mysql-pvc-pod chown: cannot read directory '/var/lib/mysql/data': Permission denied chown: cannot read directory '/var/lib/mysql/init': Permission deniedNarayana Basetty
MySQL will by default try to make itself the owner of datadir which is denied by your OS. Is selinux enabled? run sestatus.Baroudi Safwen
sestatus - enabled by default, what is the fix, do i need to doNarayana Basetty

1 Answers

0
votes

try to give the world write permission with sticky bit set. then re-create the pod

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

Thank -SR