如何调试其状态为何为CrashLoopBackOff?
我没有在minisube上使用Aws Kubernetes实例。
我遵循了本教程。 https://github.com/mkjelland/spring-boot-postgres-on-k8s-sample
当我这样做
var count = 1;
window.call1 = function() {
const button = $("#btn1 polygon");
console.log(count);
count = count % 3 + 1;
switch (count) {
case 1:
button.css("fill", "red");
break;
case 2:
button.css("fill", "blue");
break;
case 3:
button.css("fill", "green");
break;
}
}
并通过
检查状态 kubectl create -f specs/spring-boot-app.yml
给出
kubectl get pods
命令下方
spring-boot-postgres-sample-67f9cbc8c-qnkzg 0/1 CrashLoopBackOff 14 50m
给予
kubectl describe pods spring-boot-postgres-sample-67f9cbc8c-qnkzg
命令 kubectl get pods --all-namespaces 提供
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning BackOff 3m18s (x350 over 78m) kubelet, ip-172-31-11-87 Back-off restarting failed container
命令 kubectl记录spring-boot-postgres-sample-667f87cf4c-858rx 什么都不打印。
答案 0 :(得分:1)
首先,我通过postgres部署修复了“ pod具有未绑定的PersistentVolumeClaims”错误,因此我通过这篇文章修复了该错误 pod has unbound PersistentVolumeClaims
现在我的postgres部署正在运行。
kubectl记录spring-boot-postgres-sample-67f9cbc8c-qnkzg 不会输出任何内容,这意味着配置文件中有问题。 kubectl描述了pod spring-boot-postgres-sample-67f9cbc8c-qnkzg ,指出容器已终止且原因已完成, 我通过运行容器无限时间来修复它 通过添加
# Just sleep forever
command: [ "sleep" ]
args: [ "infinity" ]
因此,现在我的部署正在运行。 但是现在我通过
公开了我的服务kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer --port=8080
但是无法获取External-Ip,所以我做到了
kubectl patch svc <svc-name> -n <namespace> -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.31.71.218"]}}'
所以我得到的外部IP为“ 172.31.71.218”
但是现在的问题是卷曲http://172.31.71.218:8080/超时了
我做错了什么吗?
这是我的部署文件。yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: spring-boot-postgres-sample
namespace: default
spec:
replicas: 1
template:
metadata:
name: spring-boot-postgres-sample
labels:
app: spring-boot-postgres-sample
spec:
containers:
- name: spring-boot-postgres-sample
command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
env:
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: postgres-config
key: postgres_user
- name: POSTGRES_PASSWORD
valueFrom:
configMapKeyRef:
name: postgres-config
key: postgres_password
- name: POSTGRES_HOST
valueFrom:
configMapKeyRef:
name: hostname-config
key: postgres_host
image: <mydockerHUbaccount>/spring-boot-postgres-on-k8s:v1
这是我的postgres.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
namespace: default
data:
postgres_user: postgresuser
postgres_password: password
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres
spec:
template:
metadata:
labels:
app: postgres
spec:
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pv-claim
containers:
- image: postgres
name: postgres
env:
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: postgres-config
key: postgres_user
- name: POSTGRES_PASSWORD
valueFrom:
configMapKeyRef:
name: postgres-config
key: postgres_password
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- containerPort: 5432
name: postgres
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
type: ClusterIP
ports:
- port: 5432
selector:
app: postgres
这是我如何获取主机配置图
kubectl create configmap hostname-config --from-literal=postgres_host=$(kubectl get svc postgres -o jsonpath="{.spec.clusterIP}")
答案 1 :(得分:0)
我能够重现该场景。应用程序和Postgres DB之间似乎存在连接问题。因此该应用无法启动。请在下面找到日志,这可能会对您有所帮助。
$ kubectl get po
NAME READY STATUS RESTARTS AGE
spring-boot-postgres-sample-5d7c85d98b-qwvjr 0/1 CrashLoopBackOff 19 1h
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2019-05-23 10:53:01.889 ERROR 1 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
org.postgresql.util.PSQLException: Connection to :5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
答案 2 :(得分:0)
你为什么不...
运行一个虚拟容器(运行无尽的睡眠命令)
kubectl exec -it bash
直接运行该程序,然后直接查看日志。
这是在K8上进行调试的一种简便形式。