Kubernetes Pod主机不允许连接到此mysql服务器

时间:2020-02-05 08:24:25

标签: mysql kubernetes

我正在遵循this tutorial来设置单个MySQL实例。我的Minikube仪表板中的一切都是绿色的。但是,当我尝试运行提供的命令时:

kubectl run -it --rm --image=mysql:5.7 --restart=Never mysql-client -- mysql -h mysql -ppassword

我说错了

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '172.17.0.7' is not allowed to connect to this MySQL server
pod "mysql-client" deleted
pod default/mysql-client terminated (Error)

这似乎是一个配置问题,除了我从本教程中复制了逐字记录外,但MySQL版本却达到了5.7。

我什至尝试在我的MySQL Deployment.yml中添加一个targetPort,但仍然无法正常工作:

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - protocol: TCP
    port: 3306
    targetPort: 3306
  selector:
    app: mysql
  clusterIP: None

有什么想法吗?

这是我从kubectl describe deployment mysql得到的:

Name:               mysql
Namespace:          default
CreationTimestamp:  Wed, 05 Feb 2020 00:00:29 -0800
Labels:             <none>
Annotations:        deployment.kubernetes.io/revision: 1
                    kubectl.kubernetes.io/last-applied-configuration:
                      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"mysql","namespace":"default"},"spec":{"selector":{"matchL...
Selector:           app=mysql
Replicas:           1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:       Recreate
MinReadySeconds:    0
Pod Template:
  Labels:  app=mysql
  Containers:
   mysql:
    Image:      mysql:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_ROOT_PASSWORD:  password
    Mounts:
      /var/lib/mysql from mysql-persistent-storage (rw)
  Volumes:
   mysql-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-claim
    ReadOnly:   false
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   mysql-58f698ff8b (1/1 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  3m15s  deployment-controller  Scaled up replica set mysql-58f698ff8b to 1

kubectl get pods输出:

NAME                     READY   STATUS    RESTARTS   AGE
mysql-58f698ff8b-6vld8   1/1     Running   0          33m

mysql pod日志:

2020-02-05 08:00:30+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
2020-02-05 08:00:30+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-02-05 08:00:30+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
2020-02-05T08:00:31.049182Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-05T08:00:31.050847Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 1 ...
2020-02-05T08:00:31.054488Z 0 [Note] InnoDB: PUNCH HOLE support available
2020-02-05T08:00:31.054565Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-02-05T08:00:31.054602Z 0 [Note] InnoDB: Uses event mutexes
2020-02-05T08:00:31.054630Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-02-05T08:00:31.054665Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-02-05T08:00:31.054699Z 0 [Note] InnoDB: Using Linux native AIO
2020-02-05T08:00:31.055020Z 0 [Note] InnoDB: Number of pools: 1
2020-02-05T08:00:31.055568Z 0 [Note] InnoDB: Using CPU crc32 instructions
2020-02-05T08:00:31.057070Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-02-05T08:00:31.066723Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-02-05T08:00:31.069606Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-02-05T08:00:31.085227Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2020-02-05T08:00:31.098615Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-02-05T08:00:31.098725Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-02-05T08:00:31.104690Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-02-05T08:00:31.106160Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2020-02-05T08:00:31.106326Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2020-02-05T08:00:31.106942Z 0 [Note] InnoDB: Waiting for purge to start
2020-02-05T08:00:31.157358Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 1628964
2020-02-05T08:00:31.157755Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2020-02-05T08:00:31.157848Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-02-05T08:00:31.157922Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200205  8:00:31
2020-02-05T08:00:31.162883Z 0 [Warning] System table 'plugin' is expected to be transactional.
2020-02-05T08:00:31.165053Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-05T08:00:31.168407Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2020-02-05T08:00:31.168424Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-02-05T08:00:31.169531Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-05T08:00:31.169841Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-02-05T08:00:31.171462Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2020-02-05T08:00:31.171795Z 0 [Note] IPv6 is available.
2020-02-05T08:00:31.172095Z 0 [Note]   - '::' resolves to '::';
2020-02-05T08:00:31.172129Z 0 [Note] Server socket created on IP: '::'.
2020-02-05T08:00:31.175361Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-02-05T08:00:31.175508Z 0 [Warning] Failed to open optimizer cost constant tables

2020-02-05T08:00:31.175965Z 0 [Warning] 'user' entry 'root@mysql-c85f7f79c-pw2mj' ignored in --skip-name-resolve mode.
2020-02-05T08:00:31.176010Z 0 [Warning] 'user' entry '@mysql-c85f7f79c-pw2mj' ignored in --skip-name-resolve mode.
2020-02-05T08:00:31.176037Z 0 [Warning] 'proxies_priv' entry '@ root@mysql-c85f7f79c-pw2mj' ignored in --skip-name-resolve mode.
2020-02-05T08:00:31.176707Z 0 [Warning] System table 'time_zone_leap_second' is expected to be transactional.
2020-02-05T08:00:31.176741Z 0 [Warning] System table 'time_zone_name' is expected to be transactional.
2020-02-05T08:00:31.176751Z 0 [Warning] System table 'time_zone' is expected to be transactional.
2020-02-05T08:00:31.176761Z 0 [Warning] System table 'time_zone_transition_type' is expected to be transactional.
2020-02-05T08:00:31.176786Z 0 [Warning] System table 'time_zone_transition' is expected to be transactional.
2020-02-05T08:00:31.177295Z 0 [Warning] System table 'servers' is expected to be transactional.
2020-02-05T08:00:31.178078Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-02-05T08:00:31.178369Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_history: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-02-05T08:00:31.178482Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_history_long: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-02-05T08:00:31.178810Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.178894Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.179608Z 0 [ERROR] Column count of performance_schema.setup_actors is wrong. Expected 5, found 3. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.179802Z 0 [ERROR] Incorrect definition of table performance_schema.setup_objects: expected column 'OBJECT_TYPE' at position 0 to have type enum('EVENT','FUNCTION','PROCEDURE','TABLE','TRIGGER', found type enum('TABLE').
2020-02-05T08:00:31.180209Z 0 [ERROR] Column count of performance_schema.table_lock_waits_summary_by_table is wrong. Expected 68, found 73. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.180302Z 0 [ERROR] Column count of performance_schema.threads is wrong. Expected 17, found 14. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.180369Z 0 [ERROR] Column count of performance_schema.events_stages_current is wrong. Expected 12, found 10. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.180438Z 0 [ERROR] Column count of performance_schema.events_stages_history is wrong. Expected 12, found 10. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.180513Z 0 [ERROR] Column count of performance_schema.events_stages_history_long is wrong. Expected 12, found 10. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.180666Z 0 [ERROR] Incorrect definition of table performance_schema.events_stages_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.180763Z 0 [ERROR] Incorrect definition of table performance_schema.events_stages_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.180952Z 0 [ERROR] Column count of performance_schema.events_statements_current is wrong. Expected 41, found 40. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.181031Z 0 [ERROR] Column count of performance_schema.events_statements_history is wrong. Expected 41, found 40. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.181193Z 0 [ERROR] Column count of performance_schema.events_statements_history_long is wrong. Expected 41, found 40. Created with MySQL 50647, now running 50729. Please use mysql_upgrade to fix this error.
2020-02-05T08:00:31.181308Z 0 [ERROR] Incorrect definition of table performance_schema.events_statements_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.181384Z 0 [ERROR] Incorrect definition of table performance_schema.events_statements_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.181641Z 0 [ERROR] Native table 'performance_schema'.'events_statements_summary_by_program' has the wrong structure
2020-02-05T08:00:31.181704Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_current' has the wrong structure
2020-02-05T08:00:31.181736Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history' has the wrong structure
2020-02-05T08:00:31.181766Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history_long' has the wrong structure
2020-02-05T08:00:31.181801Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_thread_by_event_name' has the wrong structure
2020-02-05T08:00:31.181860Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_account_by_event_name' has the wrong structure
2020-02-05T08:00:31.181919Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_user_by_event_name' has the wrong structure
2020-02-05T08:00:31.181945Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_host_by_event_name' has the wrong structure
2020-02-05T08:00:31.181981Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_global_by_event_name' has the wrong structure
2020-02-05T08:00:31.182046Z 0 [ERROR] Incorrect definition of table performance_schema.users: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.182166Z 0 [ERROR] Incorrect definition of table performance_schema.accounts: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-02-05T08:00:31.182604Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_global_by_event_name' has the wrong structure
2020-02-05T08:00:31.182659Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_account_by_event_name' has the wrong structure
2020-02-05T08:00:31.182696Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_host_by_event_name' has the wrong structure
2020-02-05T08:00:31.182750Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_thread_by_event_name' has the wrong structure
2020-02-05T08:00:31.182786Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_user_by_event_name' has the wrong structure
2020-02-05T08:00:31.182849Z 0 [ERROR] Native table 'performance_schema'.'table_handles' has the wrong structure
2020-02-05T08:00:31.182882Z 0 [ERROR] Native table 'performance_schema'.'metadata_locks' has the wrong structure
2020-02-05T08:00:31.182919Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_configuration' has the wrong structure
2020-02-05T08:00:31.182951Z 0 [ERROR] Native table 'performance_schema'.'replication_group_members' has the wrong structure
2020-02-05T08:00:31.182987Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_status' has the wrong structure
2020-02-05T08:00:31.183023Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_configuration' has the wrong structure
2020-02-05T08:00:31.183075Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status' has the wrong structure
2020-02-05T08:00:31.183174Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status_by_coordinator' has the wrong structure
2020-02-05T08:00:31.183214Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status_by_worker' has the wrong structure
2020-02-05T08:00:31.183250Z 0 [ERROR] Native table 'performance_schema'.'replication_group_member_stats' has the wrong structure
2020-02-05T08:00:31.183281Z 0 [ERROR] Native table 'performance_schema'.'prepared_statements_instances' has the wrong structure
2020-02-05T08:00:31.183338Z 0 [ERROR] Native table 'performance_schema'.'user_variables_by_thread' has the wrong structure
2020-02-05T08:00:31.183401Z 0 [ERROR] Native table 'performance_schema'.'status_by_account' has the wrong structure
2020-02-05T08:00:31.183431Z 0 [ERROR] Native table 'performance_schema'.'status_by_host' has the wrong structure
2020-02-05T08:00:31.183460Z 0 [ERROR] Native table 'performance_schema'.'status_by_thread' has the wrong structure
2020-02-05T08:00:31.183496Z 0 [ERROR] Native table 'performance_schema'.'status_by_user' has the wrong structure
2020-02-05T08:00:31.183539Z 0 [ERROR] Native table 'performance_schema'.'global_status' has the wrong structure
2020-02-05T08:00:31.183570Z 0 [ERROR] Native table 'performance_schema'.'session_status' has the wrong structure
2020-02-05T08:00:31.183626Z 0 [ERROR] Native table 'performance_schema'.'variables_by_thread' has the wrong structure
2020-02-05T08:00:31.183691Z 0 [ERROR] Native table 'performance_schema'.'global_variables' has the wrong structure
2020-02-05T08:00:31.183728Z 0 [ERROR] Native table 'performance_schema'.'session_variables' has the wrong structure
2020-02-05T08:00:31.183834Z 0 [ERROR] Incorrect definition of table mysql.db: expected column 'User' at position 2 to have type char(32), found type char(16).
2020-02-05T08:00:31.183867Z 0 [ERROR] mysql.user has no `Event_priv` column at position 28
2020-02-05T08:00:31.184013Z 0 [ERROR] Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
2020-02-05T08:00:31.184243Z 0 [Note] mysqld: ready for connections.
Version: '5.7.29'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

2 个答案:

答案 0 :(得分:1)

我拆除了Persistent Volumes,然后重新启动了Minikube,这似乎已经解决了这个问题……出现了一些奇怪的现象,但是我要称之为一天。

答案 1 :(得分:0)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  selector:
    matchLabels:
      app: mysql
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: sql-pv-claim

这个正在为我工​​作。

您可以通过以下方式在pod内ssh

kubectl exec -it <pod name> -- /bin/bash