我在 AWS 中设置了一个 kubernetes 集群。 我们正在使用 EC2 容器注册表来存储我们的 docker 镜像。 我们已经完成了主/从属的所有设置,并且一切似乎都在与集群一起工作。
我的规范文件如下:
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 数据库。
我想我的第一个问题是这个规范文件看起来一切正常吗? 或者有人看到了什么不对吗?
我执行 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 似乎重新启动了,它会再次显示 Initializing database..
几天前,当我运行 kubectl logs 时,它会立即返回所有内容并且速度非常快,现在它非常慢并且没有真正显示任何内容我根本没有真正更改我的规范文件所以我不知道是什么正在进行。在我看来,当容器确实显示一些日志时,它似乎没有正确执行……但我不确定。
如果有人知道如何使用我可以运行的一些命令进一步调试它,将不胜感激。我在这一点上非常困惑,已经谷歌了很多但没有运气。
谢谢!
最佳答案
我在 aws 上使用 kubernetes 时出现无用错误的经验
Error from server: dial unix /var/run/docker.sock: no such file or directory
由 choosing a more hefty aws cluster instance type 解决...这是相关的环境变量
export MASTER_SIZE=t2.medium
export NODE_SIZE=t2.medium
export NUM_NODES=2 # if not defined aws will auto guess
...还删除标记 resources
下的资源限制设置的提及,直到它运行正常为止
以下命令是必不可少的...如果您不使用,请不要提及命名空间
kubectl describe svc --namespace=xxx
kubectl get pods --namespace=xxx
kubectl describe 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
这将使用默认编辑器在您的终端中打开一个编辑 session ,您可以在其中随意更改设置
我发现在对数据库部署进行故障排除时,使用下面的 Dockerfile 启动图像也很方便……这允许您使用 exec 登录
kubectl exec -ti $(kubectl get pods --namespace=${PROJECT_ID}|grep ${GKE_NODEDEPLOYMENT}|cut -d' ' -f1) --namespace=${PROJECT_ID} -c ${GKE_NGINX} -- bash
您可以在其中自由进行交互式数据库登录 session (一旦您安装了所需的客户端代码或将其放入 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
#
#
关于mysql - kubernetes 和一般调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38356549/