kubectl get deployment -n alpha
kubectl get deployment *****-deployment -n alpha -o json
kubectl rollout history deployment *****-deployment -n alpha #View previous rollout revisions and configurations.
kubectl rollout history deployment ******-deployment -n alpha --revision=4 # --revision=0:See the details, including podTemplate of the revision specified
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
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)
kubectl get svc -n alpha
kubectl get svc ****** -n alpha -o json | ConvertFrom-Json
$Port=$Service.spec.ports[0].port:
$ServiceName=$Service.metadata.name
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
$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
#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
# 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
docker images docker rmi -f $ImageId
#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
#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