0

I am writing a simple YAML file to apply liveness probe using a TCP port on Centos.6

  1. I pulled a centos:6 image from public repository
  2. started a container using the image.
  3. installed mysql, and started it to verify a opened port (3306)
  4. committed to local repository as "mysql-test:v0.1"

and apply a pod as below

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: mysql-test
  name: mysql-test-exec
spec:
  containers:
  - name: mysql-test
    args:
    - /sbin/service
    - mysqld
    - start
    image: mysql-test:v0.1
    livenessProbe:
      tcpSocket:
        port: 3306
      initialDelaySeconds: 15
      periodSeconds: 20

But, the status of the pod is CrashLoopBackOff, and the status of the container on work02 is Exited.

1) master node

root@kubeadm-master01:~# kubectl get pods 
NAME              READY     STATUS             RESTARTS   AGE
mysql-test-exec   0/1       CrashLoopBackOff   6          8m

root@kubeadm-master01:~# kubectl describe pod mysql-test-exec
.
.
.
Events:
  FirstSeen     LastSeen        Count   From                    SubObjectPath                   Type            Reason          Message
  ---------     --------        -----   ----                    -------------                   --------        ------          -------
  1m            1m              1       default-scheduler                                       Normal          Scheduled       Successfully assigned mysql-test-exec to kubeadm-work02
  1m            1m              1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal          Created         Created container with id abbad6585021151cd86fdfb3a9f733245f603686c90f533f23
44397c97c36918
  1m            1m              1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal          Started         Started container with id abbad6585021151cd86fdfb3a9f733245f603686c90f533f23
44397c97c36918
  1m            1m              1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal          Started         Started container with id a1062083089eed109fe8f41344136631bb9d4c08a2c6454dc7
7f677f01a48666
  1m            1m              1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal          Created         Created container with id a1062083089eed109fe8f41344136631bb9d4c08a2c6454dc7
7f677f01a48666
  1m            1m              3       kubelet, kubeadm-work02                                 Warning         FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" wit
h CrashLoopBackOff: "Back-off 10s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

  1m    1m      1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal  Created         Created container with id 79512aeaf8a6b4692e11b344adb24763343bb2a06c9003222097962822d42202
  1m    1m      1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal  Started         Started container with id 79512aeaf8a6b4692e11b344adb24763343bb2a06c9003222097962822d42202
  1m    43s     3       kubelet, kubeadm-work02                                 Warning FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" with CrashLoopBackOff: "Bac
k-off 20s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

  29s   29s     1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal  Started         Started container with id 4427a3b8e5320b284ac764c1152def4ba749e4f656b3c464a472514bccf2e30e
  1m    29s     4       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal  Pulled          Container image "centos-mysql:v0.1" already present on machine
  29s   29s     1       kubelet, kubeadm-work02 spec.containers{mysql-test}     Normal  Created         Created container with id 4427a3b8e5320b284ac764c1152def4ba749e4f656b3c464a472514bccf2e30e
  1m    10s     9       kubelet, kubeadm-work02 spec.containers{mysql-test}     Warning BackOff         Back-off restarting failed container
  27s   10s     3       kubelet, kubeadm-work02                                 Warning FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" with CrashLoopBackOff: "Bac
k-off 40s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

2) work node

root@kubeadm-work02:~# docker logs f64e20bf33a8
Starting mysqld:  [  OK  ]
jazzsir
  • 609
  • 2
  • 7
  • 14

1 Answers1

0

I have to remove the args to work with docker image. below deployment works for me.

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: mysql-test
  name: mysql-test-exec
spec:
  containers:
  - name: mysql-test   
    image: mysql:5.6
    env:
      - name: MYSQL_ROOT_PASSWORD
        value:  mysql456
    livenessProbe:
      tcpSocket:
        port: 3306
      initialDelaySeconds: 15
      periodSeconds: 20
sfgroups
  • 18,151
  • 28
  • 132
  • 204
  • Unfortunately, It's also not working. I wonder how to run mysqld at startup – jazzsir Aug 07 '17 at 01:50
  • Docker image automatically start mysqld. we just need to pass the root password. what error your getting? – sfgroups Aug 07 '17 at 01:52
  • the results were similar with before. I have a question. Even though I ran "chkconfig mysqld on", when inatalling mysql on centos-mysql:5.7 image. "docker run -tid --privileged=true -h test-mysql --name test-mysql centos-mysql:5.7 /bin/bash" didn't run mysqld at startup. So I have no choice to add ARG(- /sbin/service - mysqld - start) to YAML. I don't understand "Docker image automatically start mysqld". – jazzsir Aug 07 '17 at 02:08
  • I think your getting confused with OS and container. In the Docker container only one process will be running, in this case mysqld, it will startup automatically when you run the docker image. for testing stop the mysql in your host, `chkconfig mysqld stop`. then run this docker container. `docker run --name MYSQL802 --net=host -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysql456 -d mysql:8.0.2`. after this you can connect to mysql database. – sfgroups Aug 07 '17 at 03:00
  • Thank you for your explanation. I didn't use a image which is build only for Mysql, but I manually installed Mysql on centos:6 image, because my purpose is just to test livenessProbe(not to deploy Mysql). So I think my container is like OS. – jazzsir Aug 07 '17 at 04:36