12、删除pod中的nginx服务及service
[root@master ~]# kubectl delete deployment nginx -n kube-public
文章来源地址https://www.toymoban.com/news/detail-671429.html
[root@master ~]# kubectl delete svc -n kube-public nginx-service
13、查看endpoint的信息
[root@master ~]# kubectl get endpoints
14、修改/更新(镜像、参数......) kubectl set
例如:查看nginx的版本号:
需求:修改这个运行中的nginx的版本号
[root@master ~]# kubectl set image deployment/nginx nginx=nginx:1.11
过程中,他会先下载新的镜像进行创建,启动后删除老版本的容器
15、调整副本集的数量:kubectl scale
[root@master ~]# kubectl scale deployment nginx --replicas=5 -n default
deployment.apps/nginx scaled ## -n 指定namespace,本服务就创建在默认namespace中
16、查看详细信息:kubectl describe
16.1、显示所有的nodes的详细信息:kubectl describe nodes
[root@master ~]# kubectl describe nodes
16.2、查看某个node的详细信息
[root@master ~]# kubectl describe nodes node01
Name: node01
Roles: node
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
kubernetes.io/hostname=node01
kubernetes.io/os=linux
node-role.kubernetes.io/node=node
Annotations: flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"c2:b4:d2:1b:fa:c2"}
flannel.alpha.coreos.com/backend-type: vxlan
flannel.alpha.coreos.com/kube-subnet-manager: true
flannel.alpha.coreos.com/public-ip: 192.168.159.13
kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
node.alpha.kubernetes.io/ttl: 0
volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp: Sat, 05 Nov 2022 09:26:33 +0800
Taints: <none>
Unschedulable: false
Lease:
HolderIdentity: node01
AcquireTime: <unset>
RenewTime: Sat, 05 Nov 2022 17:10:49 +0800
Conditions:
Type Status LastHeartbeatTime LastTransitionTime Reason Message
---- ------ ----------------- ------------------ ------ -------
NetworkUnavailable False Sat, 05 Nov 2022 09:31:06 +0800 Sat, 05 Nov 2022 09:31:06 +0800 FlannelIsUp Flannel is running on this node
MemoryPressure False Sat, 05 Nov 2022 17:07:16 +0800 Sat, 05 Nov 2022 09:26:33 +0800 KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Sat, 05 Nov 2022 17:07:16 +0800 Sat, 05 Nov 2022 09:26:33 +0800 KubeletHasNoDiskPressure kubelet has no disk pressure
PIDPressure False Sat, 05 Nov 2022 17:07:16 +0800 Sat, 05 Nov 2022 09:26:33 +0800 KubeletHasSufficientPID kubelet has sufficient PID available
Ready True Sat, 05 Nov 2022 17:07:16 +0800 Sat, 05 Nov 2022 09:31:14 +0800 KubeletReady kubelet is posting ready status
Addresses:
InternalIP: 192.168.159.13
Hostname: node01
Capacity:
cpu: 2
ephemeral-storage: 15349Mi
hugepages-1Gi: 0
hugepages-2Mi: 0
memory: 3861508Ki
pods: 110
Allocatable:
cpu: 2
ephemeral-storage: 14485133698
hugepages-1Gi: 0
hugepages-2Mi: 0
memory: 3759108Ki
pods: 110
System Info:
Machine ID: 737b63dadf104cdaa76db981253e1baa
System UUID: F0114D56-06E7-3FC5-4619-BAD443CE9F72
Boot ID: ca48a336-8e26-4d35-bd9b-2f403926c2b5
Kernel Version: 3.10.0-957.el7.x86_64
OS Image: CentOS Linux 7 (Core)
Operating System: linux
Architecture: amd64
Container Runtime Version: docker://20.10.21
Kubelet Version: v1.21.3
Kube-Proxy Version: v1.21.3
PodCIDR: 10.150.2.0/24
PodCIDRs: 10.150.2.0/24
Non-terminated Pods: (6 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits Age
--------- ---- ------------ ---------- --------------- ------------- ---
default nginx-6fc77dcb7c-dq86p 0 (0%) 0 (0%) 0 (0%) 0 (0%) 45m
default nginx-6fc77dcb7c-gv9qq 0 (0%) 0 (0%) 0 (0%) 0 (0%) 45m
default nginx-6fc77dcb7c-hkcbb 0 (0%) 0 (0%) 0 (0%) 0 (0%) 49m
kube-flannel kube-flannel-ds-nj4vl 100m (5%) 100m (5%) 50Mi (1%) 50Mi (1%) 7h40m
kube-system coredns-6f6b8cc4f6-lg6hc 100m (5%) 0 (0%) 70Mi (1%) 170Mi (4%) 7h46m
kube-system kube-proxy-xd4lz 0 (0%) 0 (0%) 0 (0%) 0 (0%) 7h44m
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 200m (10%) 100m (5%)
memory 120Mi (3%) 220Mi (5%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-1Gi 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
Events: <none>
16.3、显示所有Pod的详细信息:kubectl describe pods
[root@master ~]# kubectl describe pods
16.4、显示一个pod的详细信息 :kubectl describe deploy/nginx
[root@master ~]# kubectl describe deploy/nginx
[root@master ~]# kubectl describe deploy/nginx
Name: nginx
Namespace: default
CreationTimestamp: Sat, 05 Nov 2022 16:06:47 +0800
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision: 3
Selector: app=nginx
Replicas: 5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.21
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-6fc77dcb7c (5/5 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 56m deployment-controller Scaled up replica set nginx-6fc77dcb7c to 1
Normal ScalingReplicaSet 56m deployment-controller Scaled down replica set nginx-897f8f586 to 2
Normal ScalingReplicaSet 52m (x5 over 56m) deployment-controller (combined from similar events): Scaled up replica set nginx-6fc77dcb7c to 5
16.5、显示所有svc详细信息:kubectl describe svc
[root@master ~]# kubectl describe svc
[root@master ~]# kubectl describe svc
Name: kubernetes
Namespace: default
Labels: component=apiserver
provider=kubernetes
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.125.0.1
IPs: 10.125.0.1
Port: https 443/TCP
TargetPort: 6443/TCP
Endpoints: 192.168.159.12:6443
Session Affinity: None
Events: <none>
Name: nginx-service
Namespace: default
Labels: app=nginx
Annotations: <none>
Selector: app=nginx
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.125.204.159
IPs: 10.125.204.159
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30307/TCP
Endpoints: 10.150.1.10:80,10.150.1.11:80,10.150.2.11:80 + 2 more...
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
16.6、显示指定svc的详细信息:kubectl describe svc nginx-service
[root@master ~]# kubectl describe svc nginx-service
[root@master ~]# kubectl describe svc nginx-service
Name: nginx-service
Namespace: default
Labels: app=nginx
Annotations: <none>
Selector: app=nginx
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.125.204.159
IPs: 10.125.204.159
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30307/TCP
Endpoints: 10.150.1.10:80,10.150.1.11:80,10.150.2.11:80 + 2 more...
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
16.7、显示所有namespace的详细信息:kubectl describe ns
[root@master ~]# kubectl describe ns
[root@master ~]# kubectl describe ns
Name: ceshi
Labels: kubernetes.io/metadata.name=ceshi
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
Name: default
Labels: kubernetes.io/metadata.name=default
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
Name: kube-flannel
Labels: kubernetes.io/metadata.name=kube-flannel
pod-security.kubernetes.io/enforce=privileged
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
Name: kube-node-lease
Labels: kubernetes.io/metadata.name=kube-node-lease
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
Name: kube-public
Labels: kubernetes.io/metadata.name=kube-public
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
Name: kube-system
Labels: kubernetes.io/metadata.name=kube-system
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
16.8、显示指定namespace的详细信息:kubectl describe ns kube-public
[root@master ~]# kubectl describe ns kube-public
[root@master ~]# kubectl describe ns public
Error from server (NotFound): namespaces "public" not found
[root@master ~]# kubectl describe ns kube-public
Name: kube-public
Labels: kubernetes.io/metadata.name=kube-public
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
故障现象:节点3个node 1个master1、现在创建一个pod,发现结果是pod无法创建
kubectl describe po pod_name-n namespaces
events:
调度器正常完成工作正常退出pod 创建失败,可能原因之一:资源现在问题
文章来源:https://www.toymoban.com/news/detail-671429.html
到了这里,关于k8s 常用命令(四)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!