kubernetes - 无法在 Docker/Kubernetes 容器内执行 netcat
问题描述
我正在尝试通过 Kubernetes 在 AWS 集群中部署一些 Docker 容器。我对部署本身没有任何问题,但我无法从容器内执行 netcat。
如果我进入容器 ( kubectl exec -it example-0 bash
) 并尝试执行: nc -w 1 -q 1 127.0.0.1 2181
,它会失败并显示:
(UNKNOWN) [127.0.0.1] 2181 (?) : Connection refused
这对我的一些容器来说是个问题,因为我使用 netcat 命令来实现相应的就绪探测。
例子:
部署 Zookeeper 容器:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: zookeeper
labels:
app: zookeeper
spec:
serviceName: zookeeper
replicas: 1
selector:
matchLabels:
app: zookeeper
template:
metadata:
labels:
app: zookeeper
spec:
terminationGracePeriodSeconds: 1800
nodeSelector:
proc_host: "yes"
host_role: "iw"
containers:
- name: zookeeper
image: imageregistry:443/mydomain/zookeeper
imagePullPolicy: Always
ports:
- containerPort: 2181
name: client
- containerPort: 2888
name: peer
- containerPort: 3888
name: leader-election
resources:
limits:
memory: 120Mi
requests:
cpu: "10m"
memory: 100Mi
lifecycle:
preStop:
exec:
command: ["sh", "-ce", "kill -s TERM 1; while $(kill -0 1 2>/dev/null); do sleep 1; done"]
env:
- name: LOGGING_LEVEL
value: WARN
- name: ID_OFFSET
value: "4"
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
readinessProbe:
exec:
command:
- /bin/bash
- -c
- '[ "imok" = "$(echo ruok | nc -w 1 -q 1 127.0.0.1 2181)" ]'
initialDelaySeconds: 15
timeoutSeconds: 5
volumeMounts:
- name: zookeeper
mountPath: /tmp/zookeeper
volumes:
- name: zookeeper
hostPath:
path: /var/lib/kafka/zookeeper
并且部署良好,但就绪探测失败并出现以下错误:
Readiness probe failed: (UNKNOWN) [127.0.0.1] 2181 (?) : Connection refused
我是 Kubernetes 新手,有人知道我缺少什么吗?
谢谢您的帮助。
解决方案
推荐阅读
- vue.js - Vue-router:如何在历史堆栈中返回两条相同的路线
- java - CouchbaseHttpSessionConfiguration 中的 couchbaseSessionRepository 需要一个 'com.couchbase.client.java.Bucket' 类型的 bean
- javascript - Select2 具有预选值的远程数据
- sql - 什么是磁盘结构?
- kotlin - Kotlin:检查字符串是否为数字
- python - 获取切片后,断言错误无法过滤查询
- javascript - 尝试使用 Java 脚本从 FLASK API 请求数据(POST)
- google-bigquery - 由于日期时间导致的 bq 加载错误(以毫秒为单位)
- django - 我们可以在 django 中使用“RequestContext”来更新 div 中的值吗?
- google-cloud-platform - Google Cloud Vision API(网络检测)是否限制匹配图像和网络实体的数量?