powershell以管理员身份运行
choco install kubernetes-cli
kubectl version --client
Set-ExecutionPolicy -Scope CurrentUser
RemoteSigned
A
kubectl completion powershell >> $PROFILE
用途:~.kube\config配置文件中配置了多个k8s集群,可通过以下命令随时切换k8s集群
kubectl config current-context
kubectl config use-context docker-desktop
kubectl config current-context
默认 --kubeconfig=config
statefulsets=>sts
services=>svc
pods=>po
configmaps=>cm
limitranges=>ing
persistentvolumes=>pv
persistentvolumeclaims=>pvc
kubectl get -h
kubectl explain pods
kubectl get namespaces
kubectl get node
kubectl get statefulsets
kubectl -n my-namespace get services |grep nginx
kubectl -n my-namespace get service -o wide nginx
kubectl -n my-namespace get service -o yaml nginx
kubectl -n my-namespace describe service nginx
kubectl -n my-namespace edit svc/nginx
kubectl -n my-namespace get pods
kubectl -n my-namespace logs -f nginx-9f577f598-rj427
kubectl -n my-namespace delete pod nginx-9f577f598-rj427
kubectl -n my-namespace describe pod ginx-9f577f598-rj427
使用
--previous
可以看到前一个容器的日志
使用describe
查看容器详情,可以通过Last State
、Events
- 137有特殊的含义,表示该进程由外部信号终止
- 数字137是两个数字的总和:128+x,其中x是终止进程的信号编号。在这个例子中, x等于9,这是SIGKILL的信号编号,意味着这个进程被强行终止
kubectl -n my-namespace describe pod ginx-9f577f598-rj427 --previous
kubectl -n my-namespace describe pod ginx-9f577f598-rj427
kubectl -n my-namespace delete pod nginx-9f577f598-rj427 --force --grace-period=0
参考:
KUBERNETES:24—POD托管(LIVENESSPROBE存活探针:HTTP GET探针、TCP套接字探针、EXEC探针)
kubectl -n my-namespace get deployments
kubectl -n my-namespace get deployment nginx
kubectl -n my-namespace apply -f nginx.yaml
kubectl -n my-namespace edit deployment nginx
kubectl -n my-namespace scale deployment nginx --replicas=1
kubectl -n my-namespace get cm
kubectl -n my-namespace get ing
kubectl -n my-namespace get pv
kubectl -n my-namespace get pvc
kubectl -n my-namespace exec -it nginx-9f577f598-rj427 -- /bin/sh
kubectl -n my-namespace exec -it nginx-9f577f598-rj427 -- top
kubectl -n my-namespace exec nginx-9f577f598-rj427 -- bash -c 'echo $HOME'
kubectl -n my-namespace logs -f nginx-9f577f598-rj427 |grep -C 10 "短信发送失败"
cat >> /etc/hosts << EOF
192.168.1.100 cas.example.org
EOF
apt-get update
apt-get install -y iputils-ping
apt-get install -y telnet
apt-get install -y curl
apt-get install -y wget
apt-get install -y aria2
apt-get install -y aria2
aria2c https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
tcpdump -i any host 192.168.1.100 and dst port 80 -w all.pcap
找到HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor,右键新建-字符串值,名为AutoRun,值为C:\cmd-alias.bat,保存退出。
新建C:\cmd-alias.bat文件,内容如下
@doskey kubectl-admin=kubectl --kubeconfig=C:/Users/admin/.kube/admin.kubeconfig $*
alias kubectl-admin='kubectl --kubeconfig=C:/Users/admin/.kube/admin.kubeconfig'
参考:
choco 使用详解
kubectl window
k8s——三种IP地址
windows自定义快捷命令