我目前正在使用微服务架构在 Google Cloud 上使用 Kubernetes。在集群中,我有不同的 Pod,每个 Pod 都可以使用 ClusterIp 通过 curl 与其他 Pod 通信。
我的问题是我需要使用 ClusterIp 不时调用这些 Pod 之一的端点。为此,我创建了一个 CronJob 来卷曲 pod 的端点,但它总是返回:
curl: (7) Failed to connect to xx.xx.xx.xx port 8080: Connection refused
Run Code Online (Sandbox Code Playgroud)
这是 cronJob 的 yaml。
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cronjob-test # name of the CronJob
spec:
schedule: "*/1 * * * *" # run every minute
concurrencyPolicy: Replace
jobTemplate:
spec:
template:
spec:
containers:
- name: cronjob-test
image: appropriate/curl
args:
- /bin/sh
- -c
- curl …Run Code Online (Sandbox Code Playgroud) google-cloud-platform kubernetes kubernetes-pod kubernetes-cronjob
我知道我可以定义这样的东西来在我的容器中获取 pod 名称:
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
Run Code Online (Sandbox Code Playgroud)
但是当我运行时: $kubectl get pods
我有一个不同的结果,例如:uipod-5d6795db87-cxxkg对应于<replicatset name>-cxxkg.
是否可以将全名 ( uipod-5d6795db87-cxxkg) 作为环境变量?而不仅仅是 pod 名称 ( uipod)。
非常感谢
在我的 Kubernetes 集群中,在我的数据库容器上,如果 pod 被删除,我的持久性存储(在 Digital Ocean 上动态配置)不会持久化存储。
我已将存储的回收策略从删除更改为保留,但这并没有什么区别。
这是 DB YAML 文件的副本:
apiVersion: v1
kind: Service
metadata:
name: db
namespace: hm-namespace01
app: app1
spec:
type: NodePort
ports:
- port: 5432
selector:
app: app1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hm-pv-claim
namespace: hm-namespace01
labels:
app: app1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: do-block-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1
namespace: hm-namespace01
labels:
app: app1
spec:
selector:
matchLabels:
app: app1
tier: backend
strategy:
type: Recreate …Run Code Online (Sandbox Code Playgroud) 使用 kubectl 命令行,是否可以定义确切的 pod 名称?
我试过
kubectl run $pod-name --image imageX
Run Code Online (Sandbox Code Playgroud)
但是,生成的 pod 名称类似于$pod-name-xx-yyy-nnn. 那么不使用 yaml 文件,我可以使用 kubectl CLI 定义 pod 名称吗?
注意:解决方案可以使用 netcat 或任何其他内置的 Linux 实用程序
我需要实现一个 initContainer 和 liveness 探测器,以确认我的 redis pod 已为我的一个 redis 依赖 pod 准备就绪。我已尝试使用此处提供的 netcat 解决方案作为答案( (printf "PING\r\n"; sleep 1) | nc 10.233.38.133 6379),但我收到-NOAUTH Authentication required.错误响应。有什么办法解决这个问题吗?我知道我可以在我的 Django 代码中安装 redis-cli 或创建一个管理命令,但我不想这样做。我也不想为我的 Redis 实例实现 Web 服务器并使用 curl 命令。
我们正在调查与 Azure Kubernetes 服务上的 Pod 启动缓慢相关的问题。一旦 pod 启动完成,我们将无法看到历史事件。最新的事件日志显示为<none>。
下面是一个例子:
sshuser@sandbox-ubuntu-vm:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-service-58bb6868c-rfrgr 1/1 Running 0 4h51m
sshuser@sandbox-ubuntu-vm:~$ kubectl describe pod my-service-58bb6868c-rfrgr
Name: my-service-58bb6868c-rfrgr
Namespace: default
Priority: 0
Node: aks-myproject-41067869-1/10.0.1.163
Start Time: Thu, 20 Feb 2020 05:25:36 -0500
Labels: app.kubernetes.io/instance=my-service
app.kubernetes.io/name=my-service
pod-template-hash=58bb6868c
Annotations: <none>
Status: Running
IP: 10.0.1.183
IPs: <none>
Controlled By: ReplicaSet/my-service-58bb6868c
Containers:
my-service:
Container ID: docker://b366fc6459f7dc03287d62da81c9fb1ed2c30ec0ccb4b601d2eea62e644de9f9
Image: myacr.azurecr.io/myproject/microservices/my-service:0.0.48
Image ID: docker-pullable://myacr.azurecr.io/myproject/microservices/my-service@sha256:cca04f3499271ac5ae383ddccba8c3f716b8f95cd0c06042ef4d7f69626beb8d
Port: 3000/TCP
Host Port: 0/TCP
State: Running
Started: Thu, …Run Code Online (Sandbox Code Playgroud) 更新配置映射后,如何自动重启与 Daemonsets 关联的 Kubernetes pod?
根据configmap 卷挂载更新时的kubernetes文档,它会自动更新 pod。但是,我认为 Daemonsets 不会发生这种情况。我错过了什么?
下面是我的配置图
apiVersion: v1
kind: ConfigMap
metadata:
name: fluent-bit-update
namespace: default
labels:
k8s-app: fluent-bit
data:
# Configuration files: server, input, filters and output
# ======================================================
fluent-bit.conf: |
[SERVICE]
Flush 1
Log_Level info
Daemon off
Parsers_File parsers.conf
@INCLUDE input-kubernetes.conf
@INCLUDE filter-kubernetes.conf
@INCLUDE output-logaggregator.conf
input-kubernetes.conf: |
[INPUT]
Name tail
Tag kube.*
Path /var/log/containers/abc.log
Parser docker
DB /var/log/tail-containers-state.db
DB.Sync Normal
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 60
Docker_Mode On
filter-kubernetes.conf: | …Run Code Online (Sandbox Code Playgroud) 我有一个 GKE 集群并在其上部署了一些工作负载。我注意到的是,每当我这样做时kubectl get events --all-namespaces,我都看不到任何结果。kubectl describe deployment <name>也不显示任何事件。我很确定我的集群中确实发生了一些事情,因为我的所有工作负载都运行良好,而且 Stackdriver 能够完美地报告日志和 HPA 功能。但是我的活动部分是空的。为什么是这样?这是我必须在 GKE 中手动启用的功能吗?
google-cloud-platform kubernetes google-kubernetes-engine kubernetes-pod
我正在尝试从我的另一个 pod 访问所有命名空间和 pod。因此,我创建了 clusterrole、clusterrolebinding 和 service account。我能够访问唯一的客户命名空间资源。但我需要访问所有命名空间资源。是否可以?
apiVersion: v1
kind: ServiceAccount
metadata:
name: spinupcontainers
namespace: customer
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: spinupcontainers
namespace: customer
rules:
- apiGroups: [""]
resources: ["pods", "pods/exec"]
verbs: ["get", "list", "delete", "patch", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: spinupcontainers
namespace: customer
subjects:
- kind: ServiceAccount
name: spinupcontainers
roleRef:
kind: ClusterRole
name: spinupcontainers
apiGroup: rbac.authorization.k8s.io
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助解决这个问题吗?
提前致谢
目标:在每个节点上至少安排一个 pod(即“日志抓取器”)一次,但不超过一次
假设一个集群有以下节点
节点
我正在使用的 Pod
apiVersion: v1
kind: Pod
metadata:
name: log-scraper
spec:
volumes:
- name: container-log-dir
hostPath:
path: /var/log/containers
containers:
- image: "logScraper:latest"
name: log-munger
volumeMounts:
- name: container-log-dir
mountPath: /var/log/logging-app
Run Code Online (Sandbox Code Playgroud)
添加亲和性以仅选择“工作”节点(或非母节点)
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "worker"
operator: In
values:
- "true"
Run Code Online (Sandbox Code Playgroud)
问题 1:我如何确保每次node运行ONE-AND-ONLY-ONE pod类型log-scraper
问题 2:应该应用/添加哪些其他清单来实现这一目标?
kubernetes ×10
kubernetes-pod ×10
kubectl ×3
azure-aks ×1
configmap ×1
linux ×1
netcat ×1
redis ×1