设置kubectl命令补齐
yum -y install bash-completion
touch /etc/profile.d/kubectl-bash.sh
echo "source <(kubectl completion bash)" > kubectl-bash.sh
source /etc/profile
获取集群节点信息
[root@k8s-master pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 5d21h v1.16.0
k8s-node1 Ready worker 5d21h v1.16.0
k8s-node2 Ready worker 5d21h v1.16.0
设置输出不同的格式
kubectl get nodes -o wide (比kubectl get nodes得到更为详细的信息)
kubectl get nodes -o json (得到json格式的数据)
kubectl get nodes -o yaml (得到yaml格式的数据)
获得、修改节点标签
kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready master 5d21h v1.16.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
添加节点标签
kubectl lable nodes k8s-node1 disktype=ssd
删除节点标签
kubectl label nodes k8s-node2 disktype-
修改节点的roles
kubectl label nodes k8s-node2 node-role.kubernetes.io/worker=
#修改名字为worker
namespace
[root@k8s-master pods]# kubectl get namespaces
NAME STATUS AGE
default Active 6d2h
kube-node-lease Active 6d2h
kube-public Active 6d2h
kube-system Active 6d2h
nginx-ingress Active 6d1h
#查看所有的命名空间
kubectl create namespace demo
#创建命名空间
kubectl delete namespace demo
#删除命名空间
创建属于不同命名空间的pod
vim nginx-namespace.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: demo
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
#前提是已经创建了相应的namespace
查看不同namespace的pod
kubectl get pod --namespace demo
创建context
kubectl config set-context demo --user=rourou --cluster=rourou --namespace=demo
##查看context
kubectl config get-contexts
网友评论