kubectl基础支持
1 2 | kubectl get deployment - n alpha kubectl get deployment * * * * * - deployment - n alpha - o json |
1 | kubectl rollout history deployment * * * * * - deployment - n alpha #View previous rollout revisions and configurations. |
1 | kubectl rollout history deployment * * * * * * - deployment - n alpha - - revision = 4 # <strong><a id="--revision" class="in-doc" href="https://www.mankier.com/1/kubectl-rollout-history#--revision" rel="noopener nofollow">--revision</a></strong>=0:See the details, including podTemplate of the revision specified |
1 | kubectl rollout undo deployment * * * * * - deployment - n alpha - - to - revision = 5 # Rollback to the previous deployment --to-revision:The revision to rollback to. Default to 0 (last revision) |
$Deployment.spec.selector.matchLabels:
$Deployment.spec.template.spec.containers
$DeployName=$Deployment.metadata.name
$LastDeploySince=$Deployment.metadata.creationTimestamp
1 2 | kubectl get ing - n alpha kubectl get ing * * * * * * - ingress - o json - n alpha |
$Ingress.metadata.name:
$Ingress.spec[0].rules.host:
http://$($ServiceName):$($Port)$($DeployInfo.LivenessProbeUrl)
1 2 | kubectl get svc - n alpha kubectl get svc * * * * * * - n alpha - o json | ConvertFrom - Json |
$Port=$Service.spec.ports[0].port:
$ServiceName=$Service.metadata.name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ConvertTo - Json $ Object - Depth 100 |kubectl - n $DestNS apply - f - #replace ConfigMaps|Secrets|Services|Deployments|Cronjobs|Ingresses kubectl get $ResourceType - n $DestNS - o json|ConvertFrom - Json #replace ConfigMaps|Secrets kubectl describe configmaps * * * * * - config - n alpha kubectl describe secret * * * * * * - secret - n alpha #$ConfigMap.metadata.name #$ConfigMap.data.PSObject.Properties #$secret.metadata.name #$secret.data.PSObject.Properties |
1 2 3 4 5 6 7 8 9 10 11 12 | $JSObject = $(kubectl - n $SourceNS get $ResourceType $ObjectName - o json|ConvertFrom - Json) #ResourceType :ConfigMaps|Secrets|Services|Deployments|Cronjobs|Ingresses $JSObject.metadata.PSObject.Properties.Remove( 'namespace' ) $JSObject.metadata.PSObject.Properties.Remove( 'creationTimestamp' ) $JSObject.metadata.PSObject.Properties.Remove( 'resourceVersion' ) $JSObject.metadata.PSObject.Properties.Remove( 'selfLink' ) $JSObject.metadata.PSObject.Properties.Remove( 'uid' ) $JSObject.PSObject.Properties.Remove( 'status' ) $JSObject.spec.PSObject.Properties.Remove( 'clusterIP' ) $JSObject.metadata.name |
1 2 3 4 5 6 7 8 9 10 | #pull image from remote image docker pull $LocalImage #Pushing image from $LocalImage to $RemoteImageUrl docker tag $LocalImage $RemoteImageUrl docker push $RemoteImageUrl #remove local image docker rmi - f $LocalImage docker rmi - f $RemoteImageUrl |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # List the version of the deployed images from remote #deployment operate $Deploys = (kubectl get deployment - n $UserNS - o json | ConvertFrom - Json) $ImageInfo = New - Object ImageInfo; $ImageInfo. Type = "Deployment" #get from deployments array:foreach $ImageInfo.ObjectName = $Deploy.metadata.name #get from containers array:foreach $ImageInfo.Image = $Deploy.spec.template.spec.containers[ 0 ].image #get from container #cronjob operate $CronJobs = (kubectl get cronjobs - n $UserNS - o json | ConvertFrom - Json) $CronJob.spec.jobTemplate.spec.template.spec.containers $ImageInfo = New - Object ImageInfo; $ImageInfo. Type = "Job" #get from cronjobs array:foreach $ImageInfo.ObjectName = $CronJob.metadata.name #get from containers array:foreach $ImageInfo.Image = $CronJob.spec.jobTemplate.spec.template.spec.containers[ 0 ].image #get from container |
1 2 3 | docker images docker rmi - f $ImageId |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #list images $ImageIds = (docker image ls - f $ReferName - q) #get conterid $ContainerId = (docker ps - q - f $Ancesstor) #stop container docker stop $ContainerId #remove image docker image rmi - f $m #Use $PublishPath as publish path dotnet publish - c "Debug" - o $PublishPath #or Release #build image docker build - f .\Dockerfile - t $ImageName . #get image id $ReferName = "reference=" + $ImageName $ImgId = (docker image ls - f $ReferName - q) #run container docker run - d "+$EnvArgs+" " + $ImgId |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #Set the image version for the deployment $DestTag = $( $Server + "/" + $MedPath + "/" + $TagName + ":" + $TagVal) #Set $ObjectName images to $DestTag #deployment $ObjectName = $Container.name kubectl - n $UserNS set image deployment / $DeployName $ObjectName = $DestTag #cronjob $ObjectName = $CronJob.metadata.name $ReplaceCmd = "`" [{ 'op' : 'replace' , 'path' : '/spec/jobTemplate/spec/template/spec/containers/$cntIndex/image' , 'value' : '`"$DestTag`"' }]`"" kubectl - n $UserNS patch cronjob $ObjectName - - type = json - p $ReplaceCmd |
标签:
Kubernetes
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?