본문 바로가기
IT/Kubernetes

K8S Resource 팁(powershell)

by rapker 2023. 4. 6.
반응형

 

무조건 모든 pod 삭제

kubectl delete pod --all -n my-namespace

 

 

특정조건을 바탕으로 pod 삭제가 필요할 때

workflow DeleteAllPod
{
    $nsName = "my-namespace"

    $podlist = (kubectl get pod -n $nsName -o json | ConvertFrom-Json).items

    ForEach -Parallel ($pod in $podlist)
    {
        kubectl delete pod $pod.metadata.name -n $nsName
    }
}
DeleteAllPod

 

 

agones GameServer의 일부 정보만 출력

function ShowGameserverInfo
{
    $nsName = "cv-agones-dev"
    $gslist = (kubectl get gs -n $nsName -o json | ConvertFrom-Json).items

    foreach ($gs in $gslist){
        if ($gs.status.state -eq "Allocated"){
            #$gs.metadata
            #$gs.status.address
            #$gs.status.ports.port
            #$gs.metadata.annotations
            Write-Host "[" $gs.metadata.name "]"
            Write-Host "  - address:" $gs.status.address ":" $gs.status.ports.port 
            Write-Host "  - channel id:" $gs.metadata.annotations.'cv-room-chnl-id'
            Write-Host "  - secret key:" $gs.metadata.annotations.'cv-room-secret-key'
            Write-Host "  - room info:" $gs.metadata.annotations.'cv-room-info'
            Write-Host "  - normal user:" $gs.metadata.annotations.'agones.dev/sdk-cv-normal-users'
            Write-Host "  - gm users:" $gs.metadata.annotations.'agones.dev/sdk-cv-gm-users'
            Write-Host "  - debug info:" $gs.metadata.annotations.'agones.dev/sdk-cv-debug-info'
        }
    }
}
ShowGameserverInfo

 

agones Allocated된 gs들의 특정 annotation 출력

function ShowNormalUsers
{
    $nsName = "my-namespace"
    $gslist = (kubectl get gs -n $nsName -o json | ConvertFrom-Json).items

    foreach ($gs in $gslist){
        if ($gs.status.state -eq "Allocated"){
            #$gs.metadata
            Write-Host $gs.metadata.name ": normalusers:" $gs.metadata.annotations.'agones.dev/sdk-cv-normal-users'
            #$gs.metadata.annotations.cv-room-info
        }
    }
}
ShowNormalUsers
반응형
LIST