我想使用单个awk
命令在Kubernetes部署中修补所有容器模板,而无需知道其名称。这可能吗?
我知道我可以通过sed
,jq
,kubectl replace
和[*]
完成替换,但我更喜欢kubectl patch deployment mydeployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"myname","imagePullPolicy":"Always"}]}}}}'
之类的内容。表达......
针对特定容器规范的修补程序命令
apiVersion: extensions/v1beta1
kind: Deployment
spec:
replicas: 1
template:
spec:
containers:
- image: example.com/my/fancyimage:latest
imagePullPolicy: Never
name: myname
dnsPolicy: ClusterFirst
restartPolicy: Always
示例部署
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As String
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Long
Dim SaveColNdx As Integer
Dim SaveRowNdx As Long
Dim FoundData As Boolean
Dim NumberOfData As Long
FName = "E:\zdump\"
MyFile = Dir(FName & "*.txt")
Sep = vbLf
ColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
SaveRowNdx = RowNdx
Do While MyFile <> ""
Open (FName & MyFile) For Input As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
If FoundData = False Then
If InStr(TempVal, "CELL_DATA") Then
NumberOfData = Val(Right(TempVal, Len(TempVal) - Len(Left(TempVal, Len("CELL_DATA") + 1))))
End If
If InStr(TempVal, "LOOKUP_TABLE default") <> 0 Then
FoundData = True
End If
Pos = NextPos + 1
NextPos = InStr(Pos, WholeLine, Sep)
Else
If NumberOfData <> 0 Then
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
RowNdx = RowNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
NumberOfData = NumberOfData - 1
End If
End If
Wend
Wend
Close #1
FoundData = False
ColNdx = ColNdx + 1
Cells(SaveRowNdx, ColNdx).Activate
RowNdx = SaveRowNdx
MyFile = Dir()
'Debug.Print Text
Loop
答案 0 :(得分:0)
这不完全是你问的,因为我在这里使用命令行工具,但如果它出现在这里,它会节省我一些时间。所以我把它发布给其他来自搜索引擎的人。
kubectl \
--username=USERNAME \
--password=PASSWORD \
--server="https://EXAMPLE.COM" \
--insecure-skip-tls-verify=true \
--namespace=MY_NAMESPACE \
get deployments | \
grep -v NAME | cut -f1 -d" " | \
xargs kubectl \
--username=USERNAME \
--password=PASSWORD \
--server="https://EXAMPLE.COM" \
--insecure-skip-tls-verify=true \
--namespace=MY_NAMESPACE \
patch deployment \
-p='{"spec":{"template":{"spec":{"containers":[{"name":"myname","imagePullPolicy":"Always"}]}}}}'
答案 1 :(得分:0)
假设您希望这是一个持续的要求,那么达到此目的的最佳实践方法是使用AlwaysPullImages AdmissionController
AlwaysPullImages
此准入控制器修改每个新的Pod,以将图片提取策略强制设置为“始终...”。
您可以通过将其附加到--enable-admission-plugins
参数上来将其应用于api控制器