使用kubernetes访问mysql:用户root访问被拒绝

时间:2016-02-29 03:21:07

标签: java mysql docker kubernetes

我有两个pod

  • MySQL的
  • .jar文件(java的微服务服务器)

这是mysql .yaml文件

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

我使用ip 10.0.0.67:3306

公开pod mysql服务

使用此命令运行.jar文件pod

 sudo ./kubectl run lingga --image=msf4j

我收到此错误

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)
<。>在.jar文件中我有bean.xml已经将ip设置为(10.0.0.67:3306)

我只是不明白为什么它不起作用

也许有人可以帮我解决问题

我使用kubernetes和docker container

1 个答案:

答案 0 :(得分:0)

只需在数据源代码中设置密码

此数据源代码位于我的.jar文件

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

它取决于数据源的外观。