在k8s中创建redis部署时,退回重启失败的容器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在k8s中创建redis部署时,退回重启失败的容器相关的知识,希望对你有一定的参考价值。
我正在尝试使用kubernetes / redis映像在k8s中启动部署对象。但我收到错误Back-off重启失败的容器。仅使用redis映像就会出现问题,并且我能够使用postgres图像等成功运行部署。
这是配置文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deployment
spec:
replicas: 1
selector:
matchLabels:
component: redis
template:
metadata:
labels:
component: redis
spec:
containers:
- name: redis
image: kubernetes/redis
ports:
- containerPort: 6379
描述pod输出:
Name: redis-deployment-57dcf8ff69-9v8sz
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: minikube/10.0.2.15
Start Time: Sun, 10 Mar 2019 11:13:00 +0530
Labels: component=redis
pod-template-hash=57dcf8ff69
Annotations: <none>
Status: Running
IP: 172.17.0.8
Controlled By: ReplicaSet/redis-deployment-57dcf8ff69
Containers:
redis:
Container ID: docker://556544175a99da6cd704ddc5ae6e65ee0a424275872d86543bbfef6eebceff5b
Image: kubernetes/redis
Image ID: docker-pullable://kubernetes/redis@sha256:60e8254f473b1df64340da257e8e0a029c0ac67a76bdde296f11eba6cde515c7
Port: 6379/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Sun, 10 Mar 2019 20:12:26 +0530
Finished: Sun, 10 Mar 2019 20:13:28 +0530
Ready: False
Restart Count: 13
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-zqj5b (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-zqj5b:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-zqj5b
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 9h default-scheduler Successfully assigned default/redis-deployment-57dcf8ff69-9v8sz to minikube
Normal Pulling 5h (x5 over 9h) kubelet, minikube pulling image "kubernetes/redis"
Normal Pulled 5h (x5 over 5h) kubelet, minikube Successfully pulled image "kubernetes/redis"
Normal Created 5h (x5 over 5h) kubelet, minikube Created container
Normal Started 5h (x5 over 5h) kubelet, minikube Started container
Warning BackOff 5h (x53 over 5h) kubelet, minikube Back-off restarting failed container
Normal SandboxChanged 17m kubelet, minikube Pod sandbox changed, it will be killed and re-created.
Normal Pulling 11m (x4 over 16m) kubelet, minikube pulling image "kubernetes/redis"
Normal Pulled 11m (x4 over 16m) kubelet, minikube Successfully pulled image "kubernetes/redis"
Normal Created 11m (x4 over 16m) kubelet, minikube Created container
Normal Started 11m (x4 over 16m) kubelet, minikube Started container
Warning BackOff 1m (x39 over 15m) kubelet, minikube Back-off restarting failed container
我在这个例子中使用kubernetes / redis图像因为使用redis图像完全失败,因为kubectl无法从dockerhub中获取图像并且我得到的错误表示拉动图像失败。不知道为什么!
有人可以帮帮我吗。
编辑 - -
日志
kubectl.exe logs redis-deployment-57dcf8ff69-9v8sz
Could not connect to Redis at -p:6379: Name or service not known
Failed to find master.
答案
下面的配置文件对我有用。
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deployment
spec:
replicas: 1
selector:
matchLabels:
component: redis
template:
metadata:
labels:
component: redis
spec:
containers:
- name: redis
image: gcr.io/google_containers/redis:v1
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
以上是关于在k8s中创建redis部署时,退回重启失败的容器的主要内容,如果未能解决你的问题,请参考以下文章