k8s学习笔记——基本命令

1. 进入pod,获取一个交互 TTY 并运行 /bin/bash

kubectl exec -it <pod-name> -n <namespace> bash

参考:k8s 命令操作

2.创建namespace

kubectl create ns xxxx

3.查看所有namespace下的pod

kubectl get pod -A

查看特定namespace下的pod

kubectl get pod -n kube-system

查看所有的namespace

kubectl get namespace
NAME              STATUS   AGE
default           Active   4d
kube-node-lease   Active   4d
kube-public       Active   4d
kube-system       Active   4d

查看所有的service

kubectl get svc -n kube-system
NAME                                    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
chart-1645713368-kubernetes-dashboard   NodePort    10.109.3.120   <none>        443:31392/TCP            4d
kube-dns                                ClusterIP   10.96.0.10     <none>        53/UDP,53/TCP,9153/TCP   4d

编写svc

kubectl edit svc kubernetes-dashboard -n kube-system

查看所有的deployment,删除了deployment,pod也会自动删除

kubectl get deployment -A

查看所有的secret

kubectl get secrets -A

查看k8s的所有节点

kubectl get nodes --show-labels

查看所有k8s角色

kubectl get role -A
NAMESPACE              NAME                                             CREATED AT
kube-public            kubeadm:bootstrap-signer-clusterinfo             2022-02-24T13:55:25Z
kube-public            system:controller:bootstrap-signer               2022-02-24T13:55:23Z
kube-system            extension-apiserver-authentication-reader        2022-02-24T13:55:23Z
kube-system            kube-proxy                                       2022-02-24T13:55:25Z
kube-system            kubeadm:kubelet-config-1.21                      2022-02-24T13:55:24Z
kube-system            kubeadm:nodes-kubeadm-config                     2022-02-24T13:55:24Z
kube-system            system::leader-locking-kube-controller-manager   2022-02-24T13:55:23Z
kube-system            system::leader-locking-kube-scheduler            2022-02-24T13:55:23Z
kube-system            system:controller:bootstrap-signer               2022-02-24T13:55:23Z
kube-system            system:controller:cloud-provider                 2022-02-24T13:55:23Z
kube-system            system:controller:token-cleaner                  2022-02-24T13:55:23Z
kube-system            system:persistent-volume-provisioner             2022-02-24T13:55:27Z
kubernetes-dashboard   kubernetes-dashboard                             2022-03-02T16:10:23Z

查看所有的serviceaccount

kubectl get serviceaccount -A

 

4.删除pod

kubectl delete pod chart-1645714995-kubernetes-dashboard-6b6475d8db-kp7vc -n kube-system

删除pod后如果又重启,需要先删除deployment,副本中定义了pod的数量

kubectl get deployment -A
NAMESPACE     NAME                                    READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   chart-1645714995-kubernetes-dashboard   1/1     1            1           4d1h
kube-system   coredns                                 1/1     1            1           4d2h

kubectl delete deployment chart-1645714995-kubernetes-dashboard -n kube-system

5.查看pod的信息

kubectl describe pod chart-1645714995-kubernetes-dashboard-6b6475d8db-x4jxw --namespace kube-system

6.查看k8s节点外部访问地址查询

kubectl cluster-info

7.如果pod的状态是CrashLoopBackOff,可以这样查看pod的日志

kubectl logs kubernetes-dashboard-764d688cff-b4rlz -n kube-system

8.滚动重启deployment

kubectl rollout restart -n your_ns deployment your_deployment

9.调整deployment的pod副本数量,--replicas后面跟想扩容或者缩容的pod数量

kubectl scale -n your_ns deployment your_deployment --replicas=2

  

 

posted @ 2016-03-04 14:57  tonglin0325  阅读(588)  评论(0编辑  收藏  举报