gpt4 book ai didi

kubernetes - 当 kubectl 将生命周期修补到容器时,请求无效

转载 作者:行者123 更新时间:2023-12-05 05:56:45 27 4
gpt4 key购买 nike

在我的例子中,我必须先部署一个部署,然后将一个 preStop Hook 修补到 jenkins 中的部署。

我尝试使用

kubectl -n mobile patch deployment hero-orders-app --type "json" -p '[
{"op":"add","path":"/spec/template/spec/containers/0/lifecycle/preStop/exec/command","value":[]},
{"op":"add","path":"/spec/template/spec/containers/0/lifecycle/preStop/exec/command/-","value":"/bin/sleep"},
{"op":"add","path":"/spec/template/spec/containers/0/lifecycle/preStop/exec/command/-","value":"10"}]'

但它返回

the request is invaild

补丁命令是否可以添加不存在的路径?或者我需要更改其他解决方案?

这里是 hero-orders-app 部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
name: hero-orders-app$SUFFIX
namespace: $K8S_NAMESPACE
labels:
branch: $LABEL
run: hero-orders-app$SUFFIX
spec:
selector:
matchLabels:
run: hero-orders-app$SUFFIX
revisionHistoryLimit: 5
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
template:
metadata:
labels:
run: hero-orders-app$SUFFIX
namespace: $K8S_NAMESPACE
branch: $LABEL
role: hero-orders-app
spec:
dnsConfig:
options:
- name: ndots
value: "1"
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
run: hero-orders-app$SUFFIX
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: run
operator: In
values:
- hero-orders-app$SUFFIX
topologyKey: kubernetes.io/hostname
imagePullSecrets:
- name: $K8S_IMAGE_SECRETS
containers:
- name: hero-orders-$CLUSTER_NAME
image: $K8S_IMAGE
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- CHOWN
- NET_RAW
- SETPCAP
ports:
- containerPort: 3000
protocol: TCP
resources:
limits:
cpu: $K8S_CPU_LIMITS
memory: $K8S_RAM_LIMITS
requests:
cpu: $K8S_CPU_REQUESTS
memory: $K8S_RAM_REQUESTS
readinessProbe:
httpGet:
path: /gw-api/v2/_manage/health
port: 3000
initialDelaySeconds: 15
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /gw-api/v2/_manage/health
port: 3000
initialDelaySeconds: 20
timeoutSeconds: 10
periodSeconds: 45

它通过服务、pdb 和 hpa 在 AWS 上运行。

这是我的 kubectl 版本

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.9", GitCommit:"7a576bc3935a6b555e33346fd73ad77c925e9e4a", GitTreeState:"clean", BuildDate:"2021-07-15T20:56:38Z", GoVersion:"go1.15.14", Compiler:"gc", Platform:"linux/amd64"}

最佳答案

我将使用更简单的部署来演示修补生命周期 Hook ,您可以在其中使用相同的技术进行自己的部署。

apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox
command: ["ash","-c","while :; do echo $(date); sleep 1; done"]

路径到 /spec/template/spec/containers/0/lifecycle 否则你会得到响应“请求无效。”

kubectl patch deployment busybox --type json -p '[{"op":"add","path":"/spec/template/spec/containers/0/lifecycle","value":{"preStop": {"exec": {"command": ["/bin/sleep","10"]}}}}]'

deployment.apps/busybox patched

修补后,部署将重新启动。您可以执行 kubectl get deployment busybox -o yaml 来检查补丁。如果您使用相同的值再次修补,则不会有任何变化。

关于kubernetes - 当 kubectl 将生命周期修补到容器时,请求无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69083220/

27 4 0
文章推荐: aws-application-load-balancer - 基于 ALB 入口 Controller 路径的路由
文章推荐: flutter - Dart 如何实现连续输出的 web-socket
文章推荐: html - 用户选择时