# 以 ps 输出格式列出所有 pod
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-6d8d776547-jpjgk 1/1 Running 0 10m
myapp-6d8d776547-lddcv 1/1 Running 0 10m
myapp-6d8d776547-ncmss 1/1 Running 0 10m
nginx-6799fc88d8-hlcrv 1/1 Running 2 22h
test-587ddb5978-kb2x5 1/1 Running 1 12m
web-96d5df5c8-m8pzb 1/1 Running 0 15m
#以 ps 输出格式列出所有 pod 并提供更多信息(例如节点名称)
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
myapp-6d8d776547-jpjgk 1/1 Running 0 11m 10.244.2.4 k8s-node2 <none> <none>
myapp-6d8d776547-lddcv 1/1 Running 0 11m 10.244.1.7 k8s-node1 <none> <none>
myapp-6d8d776547-ncmss 1/1 Running 0 11m 10.244.1.6 k8s-node1 <none> <none>
nginx-6799fc88d8-hlcrv 1/1 Running 2 22h 10.244.1.5 k8s-node1 <none> <none>
test-587ddb5978-kb2x5 1/1 Running 1 13m 10.244.2.3 k8s-node2 <none> <none>
web-96d5df5c8-m8pzb 1/1 Running 0 15m 10.244.2.2 k8s-node2 <none> <none>
#以 ps 输出格式列出具有指定 NAME 的单个复制控制器
[root@k8s-master ~]# kubectl get deployment myapp
NAME READY UP-TO-DATE AVAILABLE AGE
myapp 3/3 3 3 13m
# 以 JSON 输出格式列出单个 Pod
[root@k8s-master ~]# kubectl get -o json pod myapp-6d8d776547-jpjgk
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"creationTimestamp": "2021-12-19T05:37:52Z",
"generateName": "myapp-6d8d776547-",
"labels": {
"app": "myapp",
"pod-template-hash": "6d8d776547"
},
"managedFields": [
{
create
#创建一个deployment类型叫web的pod
[root@k8s-master ~]# kubectl create deployment web --image nginx
deployment.apps/web created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web-96d5df5c8-m8pzb 1/1 Running 0 73s
#创建一个deployment类型叫test的pod并执行sleep 600
[root@k8s-master ~]# kubectl create deployment test --image busybox -- sleep 600
deployment.apps/test created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
test-587ddb5978-kb2x5 1/1 Running 0 23s
web-96d5df5c8-m8pzb 1/1 Running 0 2m44s
#创建3个叫myapp的pod
[root@k8s-master ~]# kubectl create deployment myapp --image nginx --replicas 3
deployment.apps/myapp created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-6d8d776547-jpjgk 1/1 Running 0 46s
myapp-6d8d776547-lddcv 1/1 Running 0 46s
myapp-6d8d776547-ncmss 1/1 Running 0 46s
test-587ddb5978-kb2x5 1/1 Running 0 3m14s
web-96d5df5c8-m8pzb 1/1 Running 0 5m35s
run
#运行一个nginxpod(默认创建pod类型)
[root@k8s-master ~]# kubectl run nginx --image nginx
pod/nginx created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 73s
#运行一个标签为"app=nginx"的pod
root@k8s-master ~]# kubectl run nginx --image nginx --labels "app=nginx" --replicas 3
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/nginx created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 20s
[root@k8s-master ~]# kubectl describe pod nginx
Name: nginx
Namespace: default
Priority: 0
Node: k8s-node2/192.168.72.143
Start Time: Sun, 19 Dec 2021 01:03:01 -0500
Labels: app=nginx
# 试运行;打印相应的 API 对象而不创建它们
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master ~]# kubectl run nginx --image nginx --dry-run=client
pod/nginx created (dry run)
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
#启动一个busybox pod并保持在前台,如果退出不要重启
[root@k8s-master ~]# kubectl run -i -t busybox --image busybox --restart=Never
If you don't see a command prompt, try pressing enter.
/ #
/ # exit
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox 0/1 Completed 0 47s
[root@k8s-master ~]#
expose
#myapp的80映射到本机的8080
[root@k8s-master ~]# kubectl expose deployment myapp --port 8080 --target-port 80
service/myapp exposed
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
myapp ClusterIP 10.107.253.102 <none> 8080/TCP 66s
nginx NodePort 10.103.18.141 <none> 80:32722/TCP 22h
[root@k8s-master ~]# curl http://10.107.253.102:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
delete
#删除具有相同名称myapp的 Pod 和服务
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-6d8d776547-jpjgk 1/1 Running 0 18m
myapp-6d8d776547-lddcv 1/1 Running 0 18m
myapp-6d8d776547-ncmss 1/1 Running 0 18m
nginx-6799fc88d8-hlcrv 1/1 Running 2 23h
test-587ddb5978-kb2x5 1/1 Running 2 20m
web-96d5df5c8-m8pzb 1/1 Running 0 22m
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26h
myapp ClusterIP 10.107.253.102 <none> 8080/TCP 13m
nginx NodePort 10.103.18.141 <none> 80:32722/TCP 23h
[root@k8s-master ~]# kubectl delete deployment,svc myapp
deployment.apps "myapp" deleted
service "myapp" deleted
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-6d8d776547-jpjgk 0/1 Terminating 0 18m
myapp-6d8d776547-lddcv 0/1 Terminating 0 18m
myapp-6d8d776547-ncmss 0/1 Terminating 0 18m
nginx-6799fc88d8-hlcrv 1/1 Running 2 23h
test-587ddb5978-kb2x5 1/1 Running 2 21m
web-96d5df5c8-m8pzb 1/1 Running 0 23m
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26h
nginx NodePort 10.103.18.141 <none> 80:32722/TCP 23h
# 删除标签 app=nginx 的 Pod 和服务
[root@k8s-master ~]# kubectl run test --image nginx --labels "app=nginx"
pod/test created
[root@k8s-master ~]# kubectl run web --image nginx --labels "app=nginx"
pod/web created
[root@k8s-master ~]# kubectl run xx --image nginx --labels "app=nginx"
pod/xx created
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 2m33s
test 1/1 Running 0 34s
web 1/1 Running 0 28s
xx 1/1 Running 0 22s
[root@k8s-master ~]# kubectl delete pod -l "app=nginx"
pod "nginx" deleted
pod "test" deleted
pod "web" deleted
pod "xx" deleted
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
#删除所以pod
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-hlcrv 1/1 Running 2 23h
test-587ddb5978-kb2x5 1/1 Running 2 22m
web-96d5df5c8-m8pzb 1/1 Running 0 25m
[root@k8s-master ~]# kubectl delete deployment --all
deployment.apps "nginx" deleted
deployment.apps "test" deleted
deployment.apps "web" deleted
[root@k8s-master ~]# kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-hlcrv 0/1 Terminating 2 23h
test-587ddb5978-kb2x5 1/1 Terminating 2 23m
web-96d5df5c8-m8pzb 0/1 Terminating 0 25m
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
scale
#将名为“nginx”的pod集缩放到 3
[root@k8s-master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-r4fnx 1/1 Running 0 29m
web 1/1 Running 0 16m
[root@k8s-master ~]# kubectl scale --replicas 3 deployment/nginx
deployment.apps/nginx scaled
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 28s
nginx-6799fc88d8-r4fnx 1/1 Running 0 30m
nginx-6799fc88d8-rnph4 1/1 Running 0 27s
web 1/1 Running 0 17m
#如果名为nginx当前大小的部署为 3,则将 mysql 扩展到 4
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 28s
nginx-6799fc88d8-r4fnx 1/1 Running 0 30m
nginx-6799fc88d8-rnph4 1/1 Running 0 27s
web 1/1 Running 0 17m
[root@k8s-master ~]# kubectl scale --current-replicas 3 --replicas 4 deployment/nginx
deployment.apps/nginx scaled
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-cvwt2 1/1 Running 0 32s
nginx-6799fc88d8-glzl4 1/1 Running 0 3m8s
nginx-6799fc88d8-r4fnx 1/1 Running 0 33m
nginx-6799fc88d8-rnph4 1/1 Running 0 3m7s
web 1/1 Running 0 20m
autoscale
#自动扩展部署“nginx”,pod 数量在 2 到 10 之间,未指定目标 CPU 利用率,因此将使用默认自动扩展策略
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 4m41s
web 1/1 Running 0 22m
[root@k8s-master ~]# kubectl autoscale deployment nginx --min 2 --max 10
horizontalpodautoscaler.autoscaling/nginx autoscaled
[root@k8s-master ~]# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
nginx Deployment/nginx <unknown>/80% 2 10 2 43s
[root@k8s-master ~]# kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 6m35s
nginx-6799fc88d8-wxdbj 1/1 Running 0 34s
web 1/1 Running 0 24m
#自动扩展复制控制器“nginx”,pod 数量在 1 到 5 之间,目标 CPU 利用率为 80%
[root@k8s-master ~]# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
nginx Deployment/nginx <unknown>/80% 2 10 2 2m35s
[root@k8s-master ~]# kubectl delete hpa nginx
horizontalpodautoscaler.autoscaling "nginx" deleted
[root@k8s-master ~]# kubectl autoscale deployment nginx --max=5 --cpu-percent=80
horizontalpodautoscaler.autoscaling/nginx autoscaled
[root@k8s-master ~]# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
nginx Deployment/nginx <unknown>/80% 1 5 2 4s
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 9m35s
nginx-6799fc88d8-wxdbj 1/1 Running 0 3m34s
web 1/1 Running 0 27m
logs
#查看deployment类型的l日志
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 12m
web 1/1 Running 0 29m
[root@k8s-master ~]# kubectl logs deployment/nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/12/20 01:59:59 [notice] 1#1: using the "epoll" event method
2021/12/20 01:59:59 [notice] 1#1: nginx/1.21.4
2021/12/20 01:59:59 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2021/12/20 01:59:59 [notice] 1#1: OS: Linux 4.18.0-257.el8.x86_64
2021/12/20 01:59:59 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/12/20 01:59:59 [notice] 1#1: start worker processes
2021/12/20 01:59:59 [notice] 1#1: start worker process 31
2021/12/20 01:59:59 [notice] 1#1: start worker process 32
attach
#从运行 pod web中获取输出;使用 'kubectl.kubernetes.io/default-container' 注释 # 选择要附加的容器,否则将选择 pod 中的第一个容器
[root@k8s-master ~]# kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-dpfnl 1/1 Running 0 2m29s
nginx-6799fc88d8-glzl4 1/1 Running 0 16m
web 1/1 Running 0 34m
[root@k8s-master ~]# kubectl attach web
Defaulting container name to web.
Use 'kubectl describe pod/web -n default' to see all of the containers in this pod.
If you don't see a command prompt, try pressing enter.
describe
#描述一个pod
[root@k8s-master ~]# kubectl describe deployment/nginx
Name: nginx
Namespace: default
CreationTimestamp: Sun, 19 Dec 2021 20:29:27 -0500
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=nginx
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-6799fc88d8 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 50m deployment-controller Scaled up replica set nginx-6799fc88d8 to 1
Normal ScalingReplicaSet 20m deployment-controller Scaled up replica set nginx-6799fc88d8 to 3
Normal ScalingReplicaSet 18m deployment-controller Scaled up replica set nginx-6799fc88d8 to 4
Normal ScalingReplicaSet 9m6s (x2 over 16m) deployment-controller Scaled down replica set nginx-6799fc88d8 to 1
Normal ScalingReplicaSet 6m13s (x2 over 14m) deployment-controller Scaled up replica set nginx-6799fc88d8 to 2
cluster-info
#打印控制平面和集群服务的地址
[root@k8s-master ~]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.72.142:6443
KubeDNS is running at https://192.168.72.142:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
exec
# 从 pod 运行“date”命令获取输出,默认使用第一个容器
[root@k8s-master ~]# kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-dpfnl 1/1 Running 0 12m
nginx-6799fc88d8-glzl4 1/1 Running 0 26m
web 1/1 Running 0 43m
[root@k8s-master ~]# kubectl exec web -- dateMon Dec 20 02:25:45 UTC 2021
[root@k8s-master ~]# kubectl exec nginx-6799fc88d8-dpfnl -- date
Mon Dec 20 02:26:12 UTC 2021
#进入pod
[root@k8s-master ~]# kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-dpfnl 1/1 Running 0 14m
nginx-6799fc88d8-glzl4 1/1 Running 0 28m
web 1/1 Running 0 46m
[root@k8s-master ~]# kubectl exec -it web -- /bin/bash
root@web:/#
#进入service
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 46h
nginx NodePort 10.103.18.141 <none> 80:32722/TCP 43h
[root@k8s-master ~]# kubectl exec -it svc/nginx /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@nginx-6799fc88d8-glzl4:/#
edit
#编辑pod(把test的标签改为app=apache)
[root@k8s-master ~]# kubectl describe pod test
Name: test
Namespace: default
Priority: 0
Node: k8s-node1/192.168.72.145
Start Time: Sun, 19 Dec 2021 21:32:01 -0500
Labels: app=nginx
[root@k8s-master ~]# kubectl edit pod/test
pod/test edited
[root@k8s-master ~]# kubectl describe pod test
Name: test
Namespace: default
Priority: 0
Node: k8s-node1/192.168.72.145
Start Time: Sun, 19 Dec 2021 21:32:01 -0500
Labels: app=apache
port-forward
#把容器的端口转发到本机
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-dpfnl 1/1 Running 0 30m
nginx-6799fc88d8-glzl4 1/1 Running 0 44m
test 1/1 Running 0 12m
web 1/1 Running 0 61m
[root@k8s-master ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:32933 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10248 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10249 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2379 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2380 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2381 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10257 0.0.0.0:*
LISTEN 0 128 0.0.0.0:32722 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10259 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:10250 *:*
LISTEN 0 128 *:6443 *:*
LISTEN 0 128 *:10256 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@k8s-master ~]# kubectl port-forward pod/web 80
Forwarding from 127.0.0.1:80 -> 80
Forwarding from [::1]:80 -> 80
[root@k8s-master ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:32933 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10248 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10249 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2379 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2380 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2381 0.0.0.0:*
LISTEN 0 128 127.0.0.1:80 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10257 0.0.0.0:*
LISTEN 0 128 0.0.0.0:32722 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10259 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:10250 *:*
LISTEN 0 128 *:6443 *:*
LISTEN 0 128 [::1]:80 [::]:*
LISTEN 0 128 *:10256 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@k8s-master ~]# curl 127.0.0.1:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 监听所有地址的80端口,转发到 pod 中的80
[root@k8s-master ~]# kubectl port-forward --address 0.0.0.0 pod/web 80
Forwarding from 0.0.0.0:80 -> 80
Handling connection for 80
Handling connection for 80
[root@k8s-master ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:32933 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10248 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10249 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2379 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 128 192.168.72.142:2380 0.0.0.0:*
LISTEN 0 128 127.0.0.1:2381 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10257 0.0.0.0:*
LISTEN 0 128 0.0.0.0:32722 0.0.0.0:*
LISTEN 0 128 127.0.0.1:10259 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:10250 *:*
LISTEN 0 128 *:6443 *:*
LISTEN 0 128 *:10256 *:*
LISTEN 0 128 [::]:22 [::]:*
cp
#把本地文件cp到pod中
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-dpfnl 1/1 Running 0 38m
nginx-6799fc88d8-glzl4 1/1 Running 0 53m
test 1/1 Running 0 20m
web 1/1 Running 0 70m
[root@k8s-master ~]# kubectl cp xk web:/tmp/
[root@k8s-master ~]# kubectl exec web -- cat /tmp/xk
大傻逼
label
# 改标签
[root@k8s-master ~]# kubectl describe pod test
Name: test
Namespace: default
Priority: 0
Node: k8s-node1/192.168.72.145
Start Time: Sun, 19 Dec 2021 21:32:01 -0500
Labels: app=apache
[root@k8s-master ~]# kubectl label --overwrite=true pod test app=nginx
pod/test labeled
[root@k8s-master ~]# kubectl describe pod testName: test
Namespace: default
Priority: 0
Node: k8s-node1/192.168.72.145
Start Time: Sun, 19 Dec 2021 21:32:01 -0500
Labels: app=nginx
#添加标签
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-glzl4 1/1 Running 0 69m
test 1/1 Running 0 37m
web 1/1 Running 0 87m
[root@k8s-master ~]# kubectl label pod test env=test
pod/test labeled
[root@k8s-master ~]# kubectl describe pod test
Name: test
Namespace: default
Priority: 0
Node: k8s-node1/192.168.72.145
Start Time: Sun, 19 Dec 2021 21:32:01 -0500
Labels: app=test
env=test
api-resources
# 查看api资源
[root@k8s-master ~]# kubectl api-resources
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
events ev v1 true Event
limitranges limits v1 true LimitRange