access mysql with kubernetes : access denied for user root

2/29/2016

i have two pod

  • mysql
  • .jar file(microservice server for java)

this is mysql .yaml file

apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels: 
    name: mysql
spec: 
  containers:
    - resources:
        limits :
          cpu: 0.5
      image: mysql
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          # change this
          value: pass
      ports: 
        - containerPort: 3306
          name: mysql
      volumeMounts:
        - name: mysqlkuber
          mountPath: /var/lib/mysql
          readOnly: false
  volumes:
    - name: mysqlkuber
      hostPath:
        path: /home/adicipta/mysqlkuber

i expose pod mysql service with ip 10.0.0.67:3306

the .jar file pod run with this commend

 sudo ./kubectl run lingga --image=msf4j

and i get this error

2016-02-29 03:11:08 INFO  ClassPathXmlApplicationContext:512 - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2401f4c3: startup date [Mon Feb 29 03:11:08 GMT 2016]; root of context hierarchy
2016-02-29 03:11:09 INFO  XmlBeanDefinitionReader:315 - Loading XML bean definitions from class path resource [Beans.xml]
2016-02-29 03:11:10 INFO  DefaultListableBeanFactory:603 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1753acfe: defining beans [dataSource,hibernateSessionFactoryBean,globalManagerDAO,baseLogicBean,interfaceAccount]; root of factory hierarchy
2016-02-29 03:11:10 INFO  DriverManagerDataSource:153 - Loaded JDBC driver: com.mysql.jdbc.Driver
2016-02-29 03:11:10 INFO  Version:37 - Hibernate Commons Annotations 3.2.0.Final
2016-02-29 03:11:10 INFO  Environment:603 - Hibernate 3.6.10.Final
2016-02-29 03:11:10 INFO  Environment:636 - hibernate.properties not found
2016-02-29 03:11:10 INFO  Environment:814 - Bytecode provider name : javassist
2016-02-29 03:11:10 INFO  Environment:695 - using JDK 1.4 java.sql.Timestamp handling
2016-02-29 03:11:10 INFO  AnnotationBinder:532 - Binding entity from annotated class: com.adins.model.Msuser
2016-02-29 03:11:10 INFO  EntityBinder:530 - Bind entity com.adins.model.Msuser on table msuser
2016-02-29 03:11:10 INFO  Configuration:1676 - Hibernate Validator not found: ignoring
2016-02-29 03:11:10 INFO  AnnotationSessionFactoryBean:780 - Building new Hibernate SessionFactory
2016-02-29 03:11:10 INFO  HibernateSearchEventListenerRegister:75 - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
2016-02-29 03:11:10 INFO  ConnectionProviderFactory:173 - Initializing connection provider: org.springframework.orm.hibernate3.TransactionAwareDataSourceConnectionProvider
2016-02-29 03:11:11 WARN  SettingsFactory:140 - Could not obtain connection metadata
java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: NO)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)

inside the .jar file i have bean.xml that already set the ip to (10.0.0.67:3306)

i just dont get it why it doesnt works

maybe someone can help me sort it out

and i use kubernetes with docker container

-- BIlly Sutomo
docker
java
kubernetes
mysql

1 Answer

2/29/2016

just set password at the datasource code

this datasource code is inside my .jar file

<property name="username" value="root" />
<property name="password" value="pass" />

it depend on how your datasource looks like.

-- BIlly Sutomo
Source: StackOverflow