mysql – kubernetes和一般调试它

我在AWS中有一个kubernetes集群设置.

我们使用EC2容器注册表来存储我们的docker镜像.

我们有master / minions所有设置,一切似乎都在使用集群.

我的spec文件如下:

apiVersion: v1
kind: Service
metadata:
  name: apim-mysql
  labels:
    app: apim
spec:
  ports:
    # the port that this service should serve on
    - port: 3306
  selector:
    app: apim
    tier: mysql
  clusterIP: None
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: apim-mysql
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: apim
        tier: mysql
    spec:
      imagePullSecrets:
        - name: myregistrykey
      containers:
      - name: mysql
        image: <This points to our EC2 Container Registry and retreives the image>
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: WSO2_ZIP_FILE
          value: wso2am-1.10.1-SNAPSHOT.zip
        - name: WSO2_VERSION
          value: 1.10.1
        - name: MYSQL_RANDOM_ROOT_PASSWORD
          value: 'yes'
        - name: MYSQL_USER
          value: username
        - name: MYSQL_USER_PASSWD
          value: password
        - name: GET_HOSTS_FROM
          value: dns
          # If your cluster config does not include a dns service, then to
          # instead access environment variables to find service host
          # info, comment out the 'value: dns' line above, and uncomment the
          # line below.
          #value: env
        ports:
        - containerPort: 3306
          name: mysql

这个容器的作用就是设置一个mysql.
我们将需要群集中的其他节点连接到此节点.
因为他们需要使用mysql DB.

我想我的第一个问题是这个spec文件看起来一切都好吗?
或者有人看错了吗?

我执行kubectl create命令并成功运行:

kubectl create -f mysql.yaml
service "apim-mysql" created
deployment "apim-mysql" created

kubectl get pods显示pod正在运行:

apim-mysql-545962574-w2qz1        1/1       Running            1          8m

我有时在做kubectl日志时出现错误,显示:

kubectl logs apim-mysql-545962574-w2qz1
Error from server: dial unix /var/run/docker.sock: no such file or directory

但最终会重新尝试它会经历……如果有人知道为什么会发生这种情况会很好.

什么时候工作得到这样的东西:

kubectl logs apim-mysql-545962574-w2qz1
Initializing database
2016-07-13T15:51:47.375052Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-13T15:51:52.029915Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-13T15:51:53.531183Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b837bd45-4911-11e6-99ba-02420af40208.
2016-07-13T15:51:53.746173Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-13T15:51:53.746621Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2016-07-13T15:52:19.891437Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2016-07-13T15:52:19.891705Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-07-13T15:52:19.891733Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-07-13T15:52:19.891778Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2016-07-13T15:52:19.891831Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
Database initialized
MySQL init process in progress...
2016-07-13T15:52:34.632188Z 0 [Note] mysqld (mysqld 5.7.13) starting as process 49 ...
2016-07-13T15:52:49.814764Z 0 [Note] InnoDB: PUNCH HOLE support available
2016-07-13T15:52:49.814846Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-07-13T15:52:49.814859Z 0 [Note] InnoDB: Uses event mutexes
2016-07-13T15:52:49.814870Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-07-13T15:52:49.814928Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-07-13T15:52:49.814932Z 0 [Note] InnoDB: Using Linux native AIO
2016-07-13T15:52:50.243657Z 0 [Note] InnoDB: Number of pools: 1
2016-07-13T15:52:52.175079Z 0 [Note] InnoDB: Using CPU crc32 instructions
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...

稍微过了一点,pod似乎重新开始,它会说再次初始化数据库..

几天前,当我运行kubectl日志时,它会立即返回所有内容并且非常快,现在它非常慢并且没有真正显示任何我没有真正改变我的spec文件所以我不知道发生了什么.对我而言,当它实际上显示一些日志时,似乎容器没有正确执行……但我不确定.

如果有人知道如何使用一些命令进一步调试,我可以运行它将非常感激.我在这一点上非常困难并且已经谷歌了很多但没有运气.

谢谢!

最佳答案 我在aws上使用kubernetes的经历,同时获得无益的错误

Error from server: dial unix /var/run/docker.sock: no such file or directory

已经解决了choosing a more hefty aws cluster instance type …这里是相关的env vars

export MASTER_SIZE=t2.medium
export NODE_SIZE=t2.medium
export NUM_NODES=2   #  if not defined aws will auto guess

…还删除标记资源下的资源限制设置,直到它运行正常

以下命令是必不可少的……如果您不使用,请不要提及命名空间

kubectl描述svc –namespace = xxx

kubectl获取pods –namespace = xxx

kubectl描述pods –namespace = xxx

kubectl描述节点

同样很好的是能够执行部署的实时编辑…首先看看你的部署..问题

kubectl get deployments  --namespace=ruptureofthemundaneplane 

……输出

NAME                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
loudspeed-deployment   1         1         1            1           1h
mongo-deployment       1         1         1            1           1h

所以现在我们知道要进行实时编辑问题的部署名称

kubectl edit deployment/mongo-deployment

这将使用默认编辑器在您的终端中打开编辑会话,您可以随意更改设置

我发现在对数据库部署进行故障排除时,它还可以使用Dockerfile下面的代码启动图像…这允许您使用exec进行登录

kubectl exec -ti $(kubectl get pods --namespace=${PROJECT_ID}|grep ${GKE_NODEDEPLOYMENT}|cut -d' ' -f1) --namespace=${PROJECT_ID} -c ${GKE_NGINX} -- bash

您可以自由地进行交互式数据库登录会话(一旦安装了所需的客户端代码或将其放入Dockerfile下面)…这里是匹配Dockerfile用于此故障排除部署容器

FROM ubuntu:16.04

ENV TERM linux
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y wget  curl

COPY .bashrc /root/

# ENTRYPOINT ["/bin/bash"]
CMD ["/bin/bash"]


#
# docker build --tag stens_ubuntu .
#
# docker run -d  stens_ubuntu  sleep infinity
#
# docker ps
#
# 
# ... find CONTAINER ID from above and put into something like this
#
# docker exec -ti 3cea1993ed28 bash
#
#
点赞