In openshift3 i am hosting Java application. i had created MYSQL and deleted and now i am trying to create MYSQL again but it is showing error "THE CONTAINER MYSQL IS CRASHING FREQUENTLY". I attached images for reference. "SQLCrash_Image" "ConsoleOutput_Image" New images:- "Monitoring&Events_Image" "Logs_image" "Monitoring&Events_Image2" Can anyone help get this resolved?
LOGS:
D:\Openshift ocCommands>oc get pods
NAME READY STATUS RESTARTS AGE
mysql-2-deploy 0/1 Error 0 9h
mysql-3-9rmt3 0/1 CrashLoopBackOff 4 2m
mysql-3-deploy 1/1 Running 0 2m
D:\Openshift ocCommands>oc logs mysql-3-9rmt3
error: Invalid MySQL username
You must either specify the following environment variables:
MYSQL_USER (regex: '^[a-zA-Z0-9_]+$')
MYSQL_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
MYSQL_DATABASE (regex: '^[a-zA-Z0-9_]+$')
Or the following environment variable:
MYSQL_ROOT_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
Or both.
Optional Settings:
MYSQL_LOWER_CASE_TABLE_NAMES (default: 0)
MYSQL_LOG_QUERIES_ENABLED (default: 0)
MYSQL_MAX_CONNECTIONS (default: 151)
MYSQL_FT_MIN_WORD_LEN (default: 4)
MYSQL_FT_MAX_WORD_LEN (default: 20)
MYSQL_AIO (default: 1)
MYSQL_KEY_BUFFER_SIZE (default: 32M or 10% of available memory)
MYSQL_MAX_ALLOWED_PACKET (default: 200M)
MYSQL_TABLE_OPEN_CACHE (default: 400)
MYSQL_SORT_BUFFER_SIZE (default: 256K)
MYSQL_READ_BUFFER_SIZE (default: 8M or 5% of available memory)
MYSQL_INNODB_BUFFER_POOL_SIZE (default: 32M or 50% of available memory)
MYSQL_INNODB_LOG_FILE_SIZE (default: 8M or 15% of available memory)
MYSQL_INNODB_LOG_BUFFER_SIZE (default: 8M or 15% of available memory)
For more information, see https://github.com/sclorg/mysql-container
How to diagnose crash loops
Here's the steps I would suggest following. If you can provide the output of the logs in each step that'll help us see the issue.
Step 1: Install the OC client
There is only so far you can go through the UI, you'll need the
oc
client to get into deeper troubleshooting.First, log into your cluster through the web interface. Choose the question mark at the top right of the screen and select 'Command Line Tools':
Follow the instructions to download and install the client.
Step 2: Show the current pods
Once you've got the client and logged in, run:
Which should show a list of the pod names. Please paste the content of the output in your question (as text, not an image!)
Step 3: Find the crashing pod and get its logs
You'll have a pod which is crashing, which will be called something like
mysql-2-6c009
. We'll need the logs from it. Paste the output of:Step 4: If you cannot find the pod, redeploy it
If you cannot see the pod any more because the deployment has failed, try running:
Then run
oc get pods
again until you see the crashing pod.Step 5: Solving the problem!
The logs show the issue, you are not specifying the environment variables required to set the database up properly. We can see the same if we check the docs on ]OpenShift - MySQL](https://docs.openshift.com/enterprise/3.0/using_images/db_images/mysql.html#environment-variables):
To set the values, try this:
This will update your deployment config with the variables. It should re-deploy automatically if you have configured it to update when the configuration changes, if it doesn't, run:
In the future, you can create the app with the environment variables set in the first place like this:
See these docs for details.
The logs show:
Tips and tricks
How pod names work
The pods have names which give some detail. Here's how they work:
This means it is the second deployment of the
msql
service. This is the pod which is orchestrating your specific deployment.This means it is the
mysql
service, deployed during the second deployment. The random six digits at the end come from the pod id, they have to be there because you could deploy many instances of a service to many pods.Looking at pods
As you get more familiar with the commandline tool, you might find yourself running
oc get pods
and similar commands a lot. If you are linux, you can use thewatch
tool to help (on Mac, just dobrew install watch
). Then run:This command will show you a live view of the pods, updated every second:
This command is super useful and you'll use it a lot!
Quickly get logs for a pod
Try this bash function:
It'll let you run a command like this:
Kudos to my buddy Praba for the last tip.
Please update the question with the relevant logs and we can take it from there!