k8s常用命令
# k8s强制删除pvc
kubectl patch pvc pvc-ea-trained-model-data -p '{"metadata":{"finalizers":null}}' -nto
1
# 批量删除被驱逐的pod
kubectl get pods -nops| grep Evicted | awk '{print $1}' | xargs kubectl delete pod -nops
1
# pod重启
无yaml文件重启
kubectl get pod {podname} -n {namespace} -o yaml | kubectl replace --force -f -
1
有yaml文件重启
kubectl replace --force -f xxx.yaml
1
# 查看dashboard token
kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token
1
# 创建镜像仓库秘钥
kubectl create secret docker-registry default-secret --docker-server=se-ds-registry.cn-hangzhou.cr.aliyuncs.com --docker-username=ikkyu@1166866785040302 --docker-password=V8aMgQY3cv -necox
1
# k3s coredns配置
k3s重启会使用默认coredns.yaml
# 污点操作
查看污点
kubectl describe node i-xrpr2qvd |grep Taints
Taints: node-role.kubernetes.io/master:NoSchedule
1
删除污点,污点名后面加减号-
kubectl taint node i-xrpr2qvd node-role.kubernetes.io/master-
# 节点标签
添加label语法
kubectl label nodes <node-name> <label-key>=<label-value>
1
kubectl label node 192.168.1.205 mem=large
查看现有node及label 通过--show-labels 选项将节点的标签显示出来
kubectl get node --show-labels
给节点删除标签的命令,删除label语法
kubectl label nodes <node-name> <label-key>-
1
上面命令中的mem-中的mem为标签的键,后面的减号表示将该标签删除
kubectl label node 192.168.1.205 mem-
# 查看pod和service网段
pod网段
kubectl get cm kubeadm-config -n kube-system -o yaml | grep -i podsub
1
# kubectl容器外执行命令
# sqlserver
sqlserver容器外导入数据库
kubectl exec -it mssql-0 -- bash -c "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw1rd' < /tmp/00.mssql_exec.sql"
1
sqlserver容器外查询数据库并过滤
kubectl exec -it mssql-0 -- bash -c "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw1rd' -Q 'SELECT Name from sys.Databases'"| grep -v master |grep -v model | grep -v tempdb | grep -v msdb | grep -v Name | grep -v ^- | grep -v ^$ | grep -v '^('
1
sqlserver容器外删除数据库
kubectl exec -it mssql-0 -- bash -c "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw1rd' -Q 'drop database k3senergymost'"
1
# mysql
mysqlPod=`kubectl get pod -n sre | grep mysql | awk '{print $1}'`
# 拷贝文件到容器中
kubectl cp inital-data/config_2022_08_30.sql -n sre $mysqlPod:/tmp
kubectl cp inital-data/portal_2022_07_19.sql -n sre $mysqlPod:/tmp
# 创建库
kubectl exec $mysqlPod -n sre -- bash -c 'mysqladmin -uroot -pP@ssw1rd create config'
kubectl exec $mysqlPod -n sre -- bash -c 'mysqladmin -uroot -pP@ssw1rd create portal'
# 执行导入脚本
kubectl exec $mysqlPod -n sre -- bash -c 'mysql -uroot -pP@ssw1rd config < /tmp/config_2022_08_30.sql'
kubectl exec $mysqlPod -n sre -- bash -c 'mysql -uroot -pP@ssw1rd portal < /tmp/portal_2022_07_19.sql'
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
#
上次更新: 2023/02/13, 13:52:57