06.K8S常用命令

K8S常用命令

1、label

添加label语法

kubectl label nodes <node-name> <label-key>=<label-value>

删除label语法

kubectl label nodes <node-name> <label-key>-

修改Label的值
语法: 需要加上–overwrite参数

kubectl label nodes <node-name> <label-key>=<label-value> --overwrite

查看现有node及label

kubectl get node --show-labels

2、apply

创建configmap

kubectl create configmap nginx-config-face --from-file=/root/services/nginx/nginx_8000.conf

查看节点状态

kubectl get pods --all-namespaces -o wide

发布一个 deployment

kubectl apply -f https://k8s.io/examples/application/deployment.yaml

查看发布状态

kubectl describe deployment nginx-deployment

获取

kubectl get deployment

删除

kubectl delete deployment nginx-deployment

3、kubectl常用命令

查看所有 pod 列表, -n 后跟 namespace, 查看指定的命名空间

kubectl get pod
kubectl get pod -n kube  
kubectl get pod -o wide

查看 RC 和 service 列表, -o wide 查看详细信息

kubectl get rc,svc
kubectl get pod,svc -o wide  
kubectl get pod <pod-name> -o yaml

显示 Node 的详细信息

kubectl describe node 192.168.0.212

显示 Pod 的详细信息, 特别是查看 pod 无法创建的时候的日志

kubectl describe pod <pod-name>
eg:
kubectl describe pod redis-master-tqds9

根据 yaml 创建资源, apply 可以重复执行,create 不行

kubectl create -f pod.yaml
kubectl apply -f pod.yaml

基于 pod.yaml 定义的名称删除 pod

kubectl delete -f pod.yaml 

删除所有包含某个 label 的pod 和 service

kubectl delete pod,svc -l name=<label-name>

删除所有 Pod

kubectl delete pod --all

查看 endpoint 列表

kubectl get endpoints

执行 pod 的 date 命令

kubectl exec <pod-name> -- date
kubectl exec <pod-name> -- bash
kubectl exec <pod-name> -- ping 10.24.51.9

通过bash获得 pod 中某个容器的TTY,相当于登录容器

kubectl exec -it <pod-name> -c <container-name> -- bash
eg:
kubectl exec -it redis-master-cln81 -- bash

查看容器的日志

kubectl logs <pod-name>
kubectl logs -f <pod-name> # 实时查看日志
kubectl log  <pod-name>  -c <container_name> # 若 pod 只有一个容器,可以不加 -c 
PLAINTEXT 复制 全屏

查看注释

kubectl explain pod
kubectl explain pod.apiVersion

创建命名空间“test-env”

kubectl create namespace test-env

kubectl get namespace #Get a list of namespaces
4、keepalive 命令
# 检查状态
systemctl status keepalived

# 查看日志
journalctl -f -u keepalived

# 查看虚拟ip
ip a

# 重启
systemctl restart keepalived.service

systemctl restart docker 

systemctl restart kubelet


 # nfs
 vim /etc/exports
 
 exportfs -arv
 
# 启动rpc
systemctl start rpcbind
#设置开机启动
systemctl enable rpcbind
 
systemctl start nfs
systemctl enable nfs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云上凯歌

好活,当赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值