Skip to main content

[Kubernetes]Easily get detail information for each node by kubectl

· One min read

Get all info:

kubectl get nodes -o json

Get podCIDR by jsonpath:

kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'

Get formatted info by go-template:

kubectl get nodes -o go-template=' {{range .items}} {{.metadata.name}}: {{"\\t"}}{{.spec.podCIDR}}{{"\\t"}}{{.status.nodeInfo.operatingSystem}}{{"\\t"}}{{.status.nodeInfo.osImage}} {{"\\n"}} {{end}}'

kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'

kubectl get nodes -o jsonpath='{.items[?(@.status.nodeInfo.operatingSystem=="windows")].spec.podCIDR}'

kubectl get pods -o jsonpath='{.items[?(@.status.phase=="Succeeded")].metadata.name}' | xargs kubectl get pod

kubectl get nodes -o go-template=' {{range .items}} {{.metadata.name}}: {{"\\t"}}{{.spec.podCIDR}}{{"\\t"}}{{.status.nodeInfo.operatingSystem}}{{"\\t"}}{{.status.nodeInfo.osImage}} {{"\\n"}} {{end}}'

kubectl get nodes -o go-template=' {{range $pod := .items}}{{if eq $pod.status.nodeInfo.operatingSystem "windows"}}{{"\\t"}} {{.metadata.name}}: {{"\\t"}}{{.spec.podCIDR}}{{"\\t"}}{{.status.nodeInfo.operatingSystem}}{{"\\t"}}{{.status.nodeInfoosImage}} {{"\\n"}} {{end}}{{end}}'

kubectl get pods -o go-template=' {{range $pod := .items}}{{if ne $pod.status.phase "Running"}} kubectl get pod -n {{$pod.metadata.namespace}} {{$pod.metadata.name}}{{"\\n"}}{{end}}{{end}}' | bash -

https://github.com/Jooho/jhouse_openshift/blob/master/docs/template/youtube_script.md

Describe Kubelet Service Parameters on Azure Windows node

· 4 min read

Query Kubelet service

Managed by nssm

<code class="language-bash line-numbers">C:\k>sc qc kubelet
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: kubelet
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\k\nssm.exe
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Kubelet
DEPENDENCIES : docker
SERVICE_START_NAME : LocalSystem

Query kubelet AppParameters by nssm

<code class="language-bash line-numbers">C:\k>nssm get kubelet Application
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

C:\k>nssm get kubelet AppParameters
c:\k\kubeletstart.ps1

Powershell scripts to start kubelet

<code class="language-powershell line-numbers">$global:MasterIP = "q1game-q1game-6adca6-e3314a8c.hcp.westus2.azmk8s.io"
$global:KubeDnsSearchPath = "svc.cluster.local"
$global:KubeDnsServiceIp = "10.0.0.10"
$global:MasterSubnet = "10.240.0.0/16"
$global:KubeClusterCIDR = "10.240.0.0/16"
$global:KubeServiceCIDR = "10.0.0.0/16"
$global:KubeBinariesVersion = "1.17.3"
$global:CNIPath = "c:\k\cni"
$global:NetworkMode = "L2Bridge"
$global:ExternalNetwork = "ext"
$global:CNIConfig = "c:\k\cni\config\$global:NetworkMode.conf"
$global:HNSModule = "c:\k\hns.psm1"
$global:VolumePluginDir = "c:\k\volumeplugins"
$global:NetworkPlugin="azure"
$global:KubeletNodeLabels="kubernetes.azure.com/role=agent,agentpool=q1win,storageprofile=managed,storagetier=Premium_LRS,kubernetes.azure.com/cluster=MC_q1game_q1game_westus2"
Write-Host "NetworkPlugin azure, starting kubelet."

# Turn off Firewall to enable pods to talk to service endpoints. (Kubelet should eventually do this)
netsh advfirewall set allprofiles state off
# startup the service

# Find if network created by CNI exists, if yes, remove it
# This is required to keep the network non-persistent behavior
# Going forward, this would be done by HNS automatically during restart of the node

$hnsNetwork = Get-HnsNetwork | ? Name -EQ azure
if ($hnsNetwork)
{
# Cleanup all containers
docker ps -q | foreach {docker rm $_ -f}

Write-Host "Cleaning up old HNS network found"
Remove-HnsNetwork $hnsNetwork
# Kill all cni instances & stale data left by cni
# Cleanup all files related to cni
taskkill /IM azure-vnet.exe /f
taskkill /IM azure-vnet-ipam.exe /f
$cnijson = [io.path]::Combine("c:\k", "azure-vnet-ipam.json")
if ((Test-Path $cnijson))
{
Remove-Item $cnijson
}
$cnilock = [io.path]::Combine("c:\k", "azure-vnet-ipam.json.lock")
if ((Test-Path $cnilock))
{
Remove-Item $cnilock
}

$cnijson = [io.path]::Combine("c:\k", "azure-vnet.json")
if ((Test-Path $cnijson))
{
Remove-Item $cnijson
}
$cnilock = [io.path]::Combine("c:\k", "azure-vnet.json.lock")
if ((Test-Path $cnilock))
{
Remove-Item $cnilock
}
}

# Restart Kubeproxy, which would wait, until the network is created
# This was fixed in 1.15, workaround still needed for 1.14 https://github.com/kubernetes/kubernetes/pull/78612
Restart-Service Kubeproxy

$env:AZURE_ENVIRONMENT_FILEPATH="c:\k\azurestackcloud.json"

c:\k\kubelet.exe --address=0.0.0.0 --anonymous-auth=false --authentication-token-webhook=true --authorization-mode=Webhook --azure-container-registry-config=c:\k\azure.json --cgroups-per-qos=false --client-ca-file=c:\k\ca.crt --cloud-config=c:\k\azure.json --cloud-provider=azure --cluster-dns=10.0.0.10 --cluster-domain=cluster.local --dynamic-config-dir=/var/lib/kubelet --enforce-node-allocatable="" --event-qps=0 --eviction-hard="" --feature-gates=RotateKubeletServerCertificate=true --hairpin-mode=promiscuous-bridge --image-gc-high-threshold=85 --image-gc-low-threshold=80 --image-pull-progress-deadline=20m --keep-terminated-pod-volumes=false --kube-reserved=cpu=100m,memory=1843Mi --kubeconfig=c:\k\config --max-pods=30 --network-plugin=cni --node-status-update-frequency=10s --non-masquerade-cidr=0.0.0.0/0 --pod-infra-container-image=kubletwin/pause --pod-max-pids=-1 --protect-kernel-defaults=true --read-only-port=0 --resolv-conf="" --rotate-certificates=false --streaming-connection-idle-timeout=4h --system-reserved=memory=2Gi --tls-cipher-suites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256 --node-labels=$global:KubeletNodeLabels --volume-plugin-dir=$global:VolumePluginDir --cni-bin-dir=c:\k\azurecni\bin --cni-conf-dir=c:\k\azurecni\netconf

Enable Hyper-V Isolation by modify kubelet parameters

1. Modify c:\k\kubeletstart.ps1 to add parameter to kubelet

--feature-gates="XXX=true,HyperVContainer=true"

2. Restart kubelet
<code class="language-bash line-numbers">C:\k>nssm restart kubelet
Kubelet: STOP: A stop control has been sent to a service that other running services are dependent on.

C:\k>sc queryex kubelet

SERVICE_NAME: kubelet
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 4044
FLAGS :

C:\k>taskkill /PID 4044 /F

C:\k>sc start kubelet

Restart the Windows node if necessary

ClustrMaps