kubectl

陈述式资源管理方法

kubernetes 集群管理集群资源的唯一入口是通过相应的方法调用apiserver的接口

kubectl 是官方的CLI命令行工具,用于与apiserver进行通信,将用户在命令行输入的命令,组织转换成apiserver能识别的信息,进而实现管理k8s各种资源的一种有效途径

kubectl命令

============================kubectl命令=======================================

k8s中文文档:http://docs.kubernetes.org.cn/683.html

#kubectl命令帮助
kubectl --help  

#kubectl 对资源的增删查操作,比较方便,但是对改的操作就不容易了

#查看版本信息
kubectl version

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.11", GitCommit:"27522a29febbcc4badac257763044d0d90c11abd", GitTreeState:"clean", BuildDate:"2021-09-15T19:21:44Z", GoVersion:"go1.15.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.11", GitCommit:"27522a29febbcc4badac257763044d0d90c11abd", GitTreeState:"clean", BuildDate:"2021-09-15T19:16:25Z", GoVersion:"go1.15.15", Compiler:"gc", Platform:"linux/amd64"}



#查看资源对象简写,太多了,就不展示了
kubectl api-resources


#查看集群信息
kubectl cluster-info

Kubernetes control plane is running at https://192.168.111.7:6443
KubeDNS is running at https://192.168.111.7:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.


#配置kubectl自动补全,这是临时性的,可以将其写入到 /root/.bashrc下   bash刷新配置
 source <(kubectl completion bash)

#node节点查看日志,太多了不展示
journalctl -u kubelet -f


---------- 基本信息查看 ----------
#命令格式
kubectl get <resource>  [-o wide|json|yaml] [-n namespace]
获取资源的相关信息,-n 指定命名空间  -o 指定输出格式

resource可以是具体资源名称,如pod nginx-xxxx  也可以是资源类型,如pod 或者 all(仅展示几种核心资源,并不完整)

--all-namespaces 或 -A :表示显示所有命名空间
--show-labels :    显示所有标签
-l app  : 仅显示标签为app的资源
-l app=nginx : 仅显示包含app=nginx标签的,且值为nginx 的资源

#查看master的资源    cs 的全称(componentstatuses)
kubect get cs   

#查看命令空间    ns 的全称 namespace  命名空间:允许不同空间的资源可以重名,但同一空间的资源不能重名
kubectl get ns

#查看default命名空间的所有资源
kubectl get all [-n defautl]

#创建命名空间app
kubectl create ns app

#查看命名空间ns
kubectl get ns

NAME              STATUS   AGE
app               Active   4s
default           Active   25h
kube-flannel      Active   24h
kube-node-lease   Active   25h
kube-public       Active   25h
kube-system       Active   25h

#删除命名空间
kubectl delete ns app

kubect get ns
NAME              STATUS   AGE
default           Active   5d6h
kube-flannel      Active   5d5h
kube-node-lease   Active   5d6h
kube-public       Active   5d6h
kube-system       Active   5d6h


#在命名空间kube-public创建副本控制器(deployment)来启动Pod(nginx-w1)

kubectl create deployment nginx-w1 --image=nginx -n kube-public



#描述某个资源的详细信息
kubectl describe deployment nginx-w1 -n kube-public

Name:                   nginx-w1
Namespace:              kube-public
CreationTimestamp:      Tue, 21 May 2024 22:40:44 +0800
Labels:                 app=nginx-w1
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx-w1
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-w1
  Containers:
   nginx:
    Image:        nginx
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-w1-578fdbcf44 (1/1 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  88s   deployment-controller  Scaled up replica set nginx-w1-578fdbcf44 to 1


kubectl describe pod nginx-wl-d47f99cb6-hv6gz -n kube-public



Name:         nginx-w1-578fdbcf44-9tmh2
Namespace:    kube-public
Priority:     0
Node:         node01/192.168.111.8
Start Time:   Tue, 21 May 2024 22:40:44 +0800
Labels:       app=nginx-w1
              pod-template-hash=578fdbcf44
Annotations:  <none>
Status:       Running
IP:           10.244.1.22
IPs:
  IP:           10.244.1.22
Controlled By:  ReplicaSet/nginx-w1-578fdbcf44
Containers:
  nginx:
    Container ID:   docker://43cbd4bbeb94b06cb40e640f0818e308afff675be59cec3f6c083714d945b9b2
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Tue, 21 May 2024 22:41:01 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-ggbkn (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-ggbkn:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-ggbkn
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m40s  default-scheduler  Successfully assigned kube-public/nginx-w1-578fdbcf44-9tmh2 to node01
  Normal  Pulling    2m40s  kubelet            Pulling image "nginx"
  Normal  Pulled     2m24s  kubelet            Successfully pulled image "nginx" in 15.87745213s
  Normal  Created    2m24s  kubelet            Created container nginx
  Normal  Started    2m24s  kubelet            Started container nginx


#查看命名空间kube-public中的pod信息
kubectl get pods  -n kube-public

NAME                        READY   STATUS    RESTARTS   AGE
nginx-w1-578fdbcf44-9tmh2   1/1     Running   0          3m33s
nginx-w1-7464d66457-4srmd   1/1     Running   0          4d12h


#kubectl exec 可以跨主机登录容器,docker exec只能在容器所在容器主机上登录
kubectl exec -it nginx-w1-578fdbcf44-9tmh2 bash -n kube-public

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@nginx-w1-578fdbcf44-9tmh2:/# 
root@nginx-w1-578fdbcf44-9tmh2:/# 
root@nginx-w1-578fdbcf44-9tmh2:/# 
root@nginx-w1-578fdbcf44-9tmh2:/# ls
bin   dev		   docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint.d  etc			 lib   media  opt  root  sbin  sys  usr
root@nginx-w1-578fdbcf44-9tmh2:/# 

#删除(重启)pod资源,由于存在deployment/rc之类的副本控制器,删除pod也会重新拉起来
kubectl delete pod nginx-w1-578fdbcf44-9tmh2 -n kube-public

kubectl get pods -n kube-public 
NAME                        READY   STATUS    RESTARTS   AGE
nginx-w1-578fdbcf44-gmdd9   1/1     Running   0          46s


#若pod无法删除,总是处于terminate状态,则要强行删除pod

kubectl delete pod <pod-name> -n <namespace> --force --grace-period=0
#grace-period表示过渡存活期,默认30s,在删除pod之前允许POD慢慢终止其上的容器进程,从而优雅退出,0表示立即终止pod

kubectl delete pod nginx-w1-578fdbcf44-gmdd9 -n kube-public --force --grace-period=0

warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "nginx-w1-578fdbcf44-gmdd9" force deleted


#扩缩容

kubectl scale deployment nginx-wl --replicas=2 -n kube-public	# 扩容

deployment.apps/nginx-w1 scaled
[root@master01 ~]#kubectl get deployment nginx-w1 -n kube-public 
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
nginx-w1   2/2     2            2           19m



kubectl scale deployment nginx-wl --replicas=1 -n kube-public	# 缩容

ubectl get deployment nginx-w1 -n kube-public 
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
nginx-w1   1/1     1            1           20m



#删除副本控制器
kubectl delete deployment nginx-w1 -n kube-public  #kubectl delete deployment nginx-w1 -n kube-public  
deployment.apps "nginx-w1" deleted

kubectl get deployments -n kube-public 
No resources found in kube-public namespace.


#项目的生命周期:创建---》发布---》更新---》回滚---》删除

#创建命令  kubectl create 
创建并运行一个或多个容器镜像
创建一个deployment 或 job来管理容器
kubectl create --help

#创建命名空间
kubectl create emmm

#启动nginx实例,暴露端口容器 80  ,设置副本数 3
Kubectl create  deployment  nginx-emmm --image=nginx:1.14 --port 80  --replicas=3  -n emmm

kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
nginx-emmm-7bcc48d894-28c9r   1/1     Running   0          3m29s
nginx-emmm-7bcc48d894-9fbvd   1/1     Running   0          3m29s
nginx-emmm-7bcc48d894-9jk65   1/1     Running   0          3m29s


kubectl get all
NAME                              READY   STATUS    RESTARTS   AGE
pod/nginx-emmm-7bcc48d894-28c9r   1/1     Running   0          4m39s
pod/nginx-emmm-7bcc48d894-9fbvd   1/1     Running   0          4m39s
pod/nginx-emmm-7bcc48d894-9jk65   1/1     Running   0          4m39s

NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-emmm   3/3     3            3           5m20s

NAME                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-emmm-7bcc48d894   3         3         3       4m39s


#发布命令	kubectl expose
将资源暴露为新的 Service
kubectl expose --help

#为deployment的nginx-emmm创建serivce,并通过service的80端口转发至容器的80端口上,Service的名称为nginx-service,类型为NodePort
kubectl expose deployment nginx-emmm  --port=80 --target-port=80 --name=nginx-service --type=NodePort  

------------------------------------------------------------------------------------------
Kubernetes 之所以需要 Service,一方面是因为 Pod 的 IP 不是固定的(Pod可能会重建),另一方面则是因为一组 Pod 实例之间总会有负载均衡的需求。
Service 通过 Label Selector 实现的对一组的 Pod 的访问。
对于容器应用而言,Kubernetes 提供了基于 VIP(虚拟IP) 的网桥的方式访问 Service,再由 Service 重定向到相应的 Pod。

service 的 type 类型:
●ClusterIP:提供一个集群内部的虚拟IP以供Pod访问(service默认类型)

●NodePort:在每个Node上打开一个端口以供外部访问,Kubernetes将会在每个Node上打开一个端口并且每个Node的端口都是一样的,通过 NodeIp:NodePort 的方式Kubernetes集群外部的程序可以访问Service。
每个端口只能是一种服务,端口范围只能是 30000-32767。

●LoadBalancer:通过设置LoadBalancer映射到云服务商提供的LoadBalancer地址。这种用法仅用于在公有云服务提供商的云平台上设置Service的场景。通过外部的负载均衡器来访问,通常在云平台部署LoadBalancer还需要额外的费用。
在service提交后,Kubernetes就会调用CloudProvider在公有云上为你创建一个负载均衡服务,并且把被代理的Pod的IP地址配置给负载均衡服务做后端。

●externalName:将service名称映射到一个DNS域名上,相当于DNS服务的CNAME记录,用于让Pod去访问集群外部的资源,它本身没有绑定任何的资源。


扩展
●port
port 是 k8s 集群内部访问service的端口,即通过 clusterIP: port 可以从 Pod 所在的 Node 上访问到 service

●nodePort
nodePort 是外部访问 k8s 集群中 service 的端口,通过 nodeIP: nodePort 可以从外部访问到某个 service。

●targetPort
targetPort 是 Pod 的端口,从 port 或 nodePort 来的流量经过 kube-proxy 反向代理负载均衡转发到后端 Pod 的 targetPort 上,最后进入容器。

●containerPort
containerPort 是 Pod 内部容器的端口,targetPort 映射到 containerPort。


------------------------------------------------------------------------------------------
#查看pod网络状态详细信息和 Service暴露的端口
kubectl get pods,svc -o wide -n emmm

NAME                              READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
pod/nginx-emmm-7bcc48d894-28c9r   1/1     Running   0          25m   10.244.1.24   node01   <none>           <none>
pod/nginx-emmm-7bcc48d894-9fbvd   1/1     Running   0          25m   10.244.1.25   node01   <none>           <none>
pod/nginx-emmm-7bcc48d894-9jk65   1/1     Running   0          25m   10.244.2.16   node02   <none>           <none>

NAME                    TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE    SELECTOR
service/nginx-service   NodePort   10.96.101.158   <none>        80:30920/TCP   8m2s   app=nginx-emmm


#修改三个nginx副本内的页面内容
kubectl exec -it nginx-emmm-7bcc48d894-28c9r bash -n emmm
echo 123 > /usr/share/html/index.html

kubectl exec -it nginx-emmm-7bcc48d894-9fbvd  bash -n emmm
echo 123 > /usr/share/html/index.html

kubectl exec -it nginx-emmm-7bcc48d894-9jk65 bash -n emmm
echo 123 > /usr/share/html/index.html

#访问 10.96.101.158 
[root@master01 ~]#curl 10.96.101.158
12345
[root@master01 ~]#curl 10.96.101.158
1234
[root@master01 ~]#curl 10.96.101.158
123
[root@master01 ~]#curl 10.96.101.158
12345






#查看关联后端的节点   
kubectl get endpoints -n emmm

NAME            ENDPOINTS                                      AGE
nginx-service   10.244.1.24:80,10.244.1.25:80,10.244.2.16:80   30m

#尝试杀掉一个nginx 

kubectl get pods -n emmm
NAME                          READY   STATUS    RESTARTS   AGE
nginx-emmm-7bcc48d894-28c9r   1/1     Running   0          50m
nginx-emmm-7bcc48d894-9fbvd   1/1     Running   0          50m
nginx-emmm-7bcc48d894-9jk65   1/1     Running   0          50m


kubectl delete pod -n emmm nginx-emmm-7bcc48d894-28c9r 
pod "nginx-emmm-7bcc48d894-28c9r" deleted


#查看endpoint,发生了改变
NAME            ENDPOINTS                                      AGE
nginx-service   10.244.1.25:80,10.244.2.16:80,10.244.2.17:80   33m



#查看 service 的描述信息
kubectl describe svc nginx  -n emmm
Name:                     nginx-service
Namespace:                emmm
Labels:                   app=nginx-emmm
Annotations:              <none>
Selector:                 app=nginx-emmm
Type:                     NodePort
IP Families:              <none>
IP:                       10.96.101.158
IPs:                      10.96.101.158
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30920/TCP
Endpoints:                10.244.1.25:80,10.244.2.16:80,10.244.2.17:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>



#在 node01 节点上操作,查看负载均衡端口

yum install ipvsadm -y
ipvsadm -Ln

TCP  127.0.0.1:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0         

TCP  192.168.111.8:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0        
 
TCP  192.168.122.1:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0        

#在 node02 节点上操作,同样方式查看负载均衡端口
yum install ipvsadm -y
ipvsadm -Ln

TCP  127.0.0.1:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0         

TCP  192.168.111.9:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0         

TCP  192.168.122.1:30920 rr
  -> 10.244.1.25:80               Masq    1      0          0         
  -> 10.244.2.16:80               Masq    1      0          0         
  -> 10.244.2.17:80               Masq    1      0          0         

#在master01操作 查看访问日志
kubectl logs nginx-emmm-7bcc48d894-28c9r
kubectl logs nginx-emmm-7bcc48d894-9fbvd
kubectl logs nginx-emmm-7bcc48d894-9jk65


#更新命令 kubectl set 
更改现有应用资源一些信息。
kubectl set --help

#获取修改模板
kubectl set image --help
Examples:
  # Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
  kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1


#查看当前 nginx 的版本号
curl  -I 192.168.111.7:30920
curl  -I 192.168.111.8:30920

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Wed, 22 May 2024 07:31:21 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 04 Dec 2018 14:44:49 GMT
Connection: keep-alive
ETag: "5c0692e1-264"
Accept-Ranges: bytes


#将nginx 版本更新为 1.15 版本
kubectl set image deployment nginx-emmm nginx=nginx:1.15 -n emmm

#处于动态监听 pod 状态,由于使用的是滚动更新方式,所以会先生成一个新的pod,然后删除一个旧的pod,往后依次类推
kubectl get pods -w -n emmmm

NAME                          READY   STATUS              RESTARTS   AGE
nginx-emmm-5f86fcf5b9-5xtkq   0/1     ContainerCreating   0          19s
nginx-emmm-7bcc48d894-9fbvd   1/1     Running             0          69m
nginx-emmm-7bcc48d894-9jk65   1/1     Running             0          69m
nginx-emmm-7bcc48d894-dn5l6   1/1     Running             0          18m
nginx-emmm-5f86fcf5b9-5xtkq   1/1     Running             0          23s
nginx-emmm-7bcc48d894-dn5l6   1/1     Terminating         0          18m
nginx-emmm-5f86fcf5b9-m2tps   0/1     Pending             0          0s
nginx-emmm-5f86fcf5b9-m2tps   0/1     Pending             0          0s
nginx-emmm-5f86fcf5b9-m2tps   0/1     ContainerCreating   0          0s
nginx-emmm-7bcc48d894-dn5l6   0/1     Terminating         0          18m
nginx-emmm-5f86fcf5b9-m2tps   1/1     Running             0          2s
nginx-emmm-7bcc48d894-9fbvd   1/1     Terminating         0          69m
nginx-emmm-5f86fcf5b9-n9n6h   0/1     Pending             0          0s
nginx-emmm-5f86fcf5b9-n9n6h   0/1     Pending             0          0s
nginx-emmm-5f86fcf5b9-n9n6h   0/1     ContainerCreating   0          0s
nginx-emmm-7bcc48d894-dn5l6   0/1     Terminating         0          18m
nginx-emmm-7bcc48d894-dn5l6   0/1     Terminating         0          18m
nginx-emmm-7bcc48d894-9fbvd   0/1     Terminating         0          69m
nginx-emmm-7bcc48d894-9fbvd   0/1     Terminating         0          69m
nginx-emmm-7bcc48d894-9fbvd   0/1     Terminating         0          69m
nginx-emmm-5f86fcf5b9-n9n6h   1/1     Running             0          24s
nginx-emmm-7bcc48d894-9jk65   1/1     Terminating         0          69m
nginx-emmm-7bcc48d894-9jk65   0/1     Terminating         0          70m
nginx-emmm-7bcc48d894-9jk65   0/1     Terminating         0          70m
nginx-emmm-7bcc48d894-9jk65   0/1     Terminating         0          70m
....




#再看更新好后的 Pod 的 ip 会改变

kubectl get pods -n emmm -o wide

NAME                              READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
pod/nginx-emmm-5f86fcf5b9-5xtkq   1/1     Running   0          11m   10.244.1.26   node01   <none>           <none>
pod/nginx-emmm-5f86fcf5b9-m2tps   1/1     Running   0          10m   10.244.1.27   node01   <none>           <none>
pod/nginx-emmm-5f86fcf5b9-n9n6h   1/1     Running   0          10m   10.244.2.18   node02   <none>           <none>




#再看 nginx 的版本号
curl  -I 192.168.111.7:30920
curl  -I 192.168.111.8:30920


HTTP/1.1 200 OK
Server: nginx/1.15.12
Date: Wed, 22 May 2024 07:49:24 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 16 Apr 2019 13:08:19 GMT
Connection: keep-alive
ETag: "5cb5d3c3-264"
Accept-Ranges: bytes


#回滚命令 kubectl rollout
对资源进行回滚管理
kubectl rollout --help


#查看历史版本
kubectl rollout history deployment nginx-emmm  -n emmm 

deployment.apps/nginx-emmm 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>


#回滚到上一个版本
kubectl rollout undo deployment/nginx-emmm -n emmm

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Thu, 23 May 2024 13:22:06 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 04 Dec 2018 14:44:49 GMT
Connection: keep-alive
ETag: "5c0692e1-264"
Accept-Ranges: bytes


#回滚到指定版本
kubectl rollect undo deployment/nginx-emmm -n emmm -to-revision=1
HTTP/1.1 200 OK
Server: nginx/1.15.12
Date: Thu, 23 May 2024 13:25:34 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 16 Apr 2019 13:08:19 GMT
Connection: keep-alive
ETag: "5cb5d3c3-264"
Accept-Ranges: bytes


#检查回滚状态
kubectl rollect status deployment/nginx-emmm -n emmm
deployment "nginx-emmm" successfully rolled out


#删除命令  kubectl delete

#删除副本控制器
kubectl delete deployment/nginx-emmm -n emmm

#删除service
kubectl delete svc nginx-service -n emmm

金丝雀发布

==============================金丝雀发布(灰度发布)=================================
Deployment控制器支持自定义控制更新过程中的滚动节奏,如“暂停(pause)”或“继续(resume)”更新操作。比如等待第一批新的Pod资源创建完成后立即暂停更新过程,此时,仅存在一部分新版本的应用,主体部分还是旧的版本。然后,再筛选一小部分的用户请求路由到新版本的Pod应用,继续观察能否稳定地按期望的方式运行。确定没问题之后再继续完成余下的Pod资源滚动更新,否则立即回滚更新操作。这就是所谓的金丝雀发布

#创建deployment
kubectl create deployment nginx --image=nginx:1.14 --port=80 --replicas=3 -n emmm
#创建service
kubectl expose -n emmm deployment/nginx  --port=80 --target-port=80 --name=nginx-service  --type=NodePort 

#更新deployment的版本,并配置暂停deployment
kubectl set image deployment/nginx nginx=:1.15 -n emmm && kubectl rollect pasue deployment/nginx -n emmm

#监控更新的过程,可以看到已经新增了一个资源,但是并未按照预期的状态去删除一个旧的资源,就是因为使用了pause暂停命令

kubectl get pods -w -n emmm -o wide

NAME                     READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE   READINESS GATES
nginx-698676d7f8-fxcqs   1/1     Running   0          5m55s   10.244.1.47   node01   <none>           <none>
nginx-d9d8cf5c7-59nmk    1/1     Running   0          11m     10.244.2.32   node02   <none>           <none>
nginx-d9d8cf5c7-r5hsv    1/1     Running   0          11m     10.244.2.33   node02   <none>           <none>
nginx-d9d8cf5c7-sd89w    1/1     Running   0          11m     10.244.1.46   node01   <none>           <none>


#修改一下nginx-d9d8cf5c7-7dtjk内nginx主页的内容

kubectl exec -it -n emmm nginx-698676d7f8-fxcqs  bash

echo 123123 > /usr/share/nginx/html/index.html

#可以查看对应版本,nginx-d9d8cf5c7-7dtjk和其他三个版本不同
curl -I 10.244.1.45
#在看看其他三个
curl -I 10.244.2.31 
curl -I 10.244.1.44
curl -I 10.244.2.30

#多访问几次
curl 192.168.111.7  
=====================================================================================
[root@master01 ~]#curl 192.168.111.7:32421
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
[root@master01 ~]#curl 192.168.111.7:32421
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
[root@master01 ~]#curl 192.168.111.7:32421
123123
[root@master01 ~]#curl 192.168.111.7:32421
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
======================================================================================

#查看标签,可以看到有个标签 pod-template和其他三个pod-template有不同之处
kubectl get pod,svc -owide --show-labels -n emmm


NAME                         READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE   READINESS GATES   LABELS
pod/nginx-d9d8cf5c7-59nmk    1/1     Running   0          10m     10.244.2.32   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-r5hsv    1/1     Running   0          10m     10.244.2.33   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-sd89w    1/1     Running   0          10m     10.244.1.46   node01   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7

NAME                        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR    LABELS
service/nginx-service       NodePort   10.96.44.163   <none>        80:31865/TCP   9m    app=nginx   app=nginx


#创建一个新的service
kubectl expose -n emmm deployment nginx --port=80 --target-port=80 --name=new-nginx-service --type=NodePort

#再次查看
kubectl get pod,svc -owide --show-labels -n emmm


NAME                         READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE   READINESS GATES   LABELS
pod/nginx-698676d7f8-fxcqs   1/1     Running   0          4m33s   10.244.1.47   node01   <none>           <none>            app=nginx,pod-template-hash=698676d7f8
pod/nginx-d9d8cf5c7-59nmk    1/1     Running   0          10m     10.244.2.32   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-r5hsv    1/1     Running   0          10m     10.244.2.33   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-sd89w    1/1     Running   0          10m     10.244.1.46   node01   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7

NAME                        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR    LABELS
service/new-nginx-service   NodePort   10.96.143.97   <none>        80:32474/TCP   65s   app=nginx   app=nginx
service/nginx-service       NodePort   10.96.44.163   <none>        80:31865/TCP   9m    app=nginx   app=nginx

#查看nginx-service 的yaml文件
kubectl edit svc -n emmm new-nginx-service

#拷贝其中的文件内容
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2024-05-23T14:36:36Z"
  labels:
    app: nginx
  name: new-nginx-service
  namespace: emmm
  resourceVersion: "88192"
  uid: b7ae9b1f-10ed-488e-a682-5253628ec97f
spec:
  clusterIP: 10.96.143.97
  clusterIPs:
  - 10.96.143.97
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32474
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

#切换 /mnt下
cd /mnt


vim new-nginx.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: new-nginx-service
  namespace: emmm
spec:
  clusterIP: 10.96.143.97
  clusterIPs:
  - 10.96.143.97
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32474
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    pod-template-hash: 698676d7f8  #将原本的app: nginx替换成   pod-template-hash: 698676d7f8 
  sessionAffinity: None
  type: NodePort

#删除new-nginx-service  
kubectl delete -n emmm svc new-nginx-service

#使用apply -f 导入yaml文件
kubectl apply -f new-nginx.yaml

#再次查看
kubectl get pod,svc -owide --show-labels -n emmm

NAME                         READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES   LABELS
pod/nginx-698676d7f8-fxcqs   1/1     Running   0          13m   10.244.1.47   node01   <none>           <none>            app=nginx,pod-template-hash=698676d7f8
pod/nginx-d9d8cf5c7-59nmk    1/1     Running   0          19m   10.244.2.32   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-r5hsv    1/1     Running   0          19m   10.244.2.33   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-sd89w    1/1     Running   0          19m   10.244.1.46   node01   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7

NAME                        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR                       LABELS
service/new-nginx-service   NodePort   10.96.143.97   <none>        80:32474/TCP   2s    pod-template-hash=698676d7f8   app=nginx
service/nginx-service       NodePort   10.96.44.163   <none>        80:31865/TCP   17m   app=nginx                      app=nginx


#使用curl -I 192.168.111.7:32474 查看版本
HTTP/1.1 200 OK
Server: nginx/1.15.12
Date: Thu, 23 May 2024 14:49:19 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 16 Apr 2019 13:08:19 GMT
Connection: keep-alive
ETag: "5cb5d3c3-264"
Accept-Ranges: bytes

#但使用31865依旧能访问到nginx1.15 ,所以需要再次操作

kubectl edit svc -n emmm nginx-service


# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2024-05-23T14:28:41Z"
  labels:
    app: nginx
  name: nginx-service
  namespace: emmm
  resourceVersion: "87501"
  uid: 40c61cb7-d77d-41d3-9427-f1ec368e667a
spec:
  clusterIP: 10.96.44.163
  clusterIPs:
  - 10.96.44.163
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31865
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

#cd /mnt下

cd /mnt

vim nginx.yaml

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2024-05-23T14:28:41Z"
  labels:
    app: nginx
  name: nginx-service
  namespace: emmm
  resourceVersion: "87501"
  uid: 40c61cb7-d77d-41d3-9427-f1ec368e667a
spec:
  clusterIP: 10.96.44.163
  clusterIPs:
  - 10.96.44.163
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31865
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    pod-template-hash: d9d8cf5c7
  sessionAffinity: None
  type: NodePort

#删除nginx-service
kubectl delete svc -n emmm nginx-service


#使用apply -f 导入
kubectl apply -f nginx.yaml

#查看状态
kubectl get pod,svc -owide --show-labels -n emmm

NAME                         READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES   LABELS
pod/nginx-698676d7f8-fxcqs   1/1     Running   0          21m   10.244.1.47   node01   <none>           <none>            app=nginx,pod-template-hash=698676d7f8
pod/nginx-d9d8cf5c7-59nmk    1/1     Running   0          27m   10.244.2.32   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-r5hsv    1/1     Running   0          27m   10.244.2.33   node02   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7
pod/nginx-d9d8cf5c7-sd89w    1/1     Running   0          27m   10.244.1.46   node01   <none>           <none>            app=nginx,pod-template-hash=d9d8cf5c7

NAME                        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE     SELECTOR                       LABELS
service/new-nginx-service   NodePort   10.96.143.97   <none>        80:32474/TCP   8m15s   pod-template-hash=698676d7f8   app=nginx
service/nginx-service       NodePort   10.96.44.163   <none>        80:31865/TCP   3s      pod-template-hash=d9d8cf5c7    app=nginx

#使用curl查看状态,多看几次,都是1.14版本
curl -I  192.168.111.7:31865

声明式资源管理方法

Kubernetes 支持 YAML 和 JSON 格式管理资源对象
JSON 格式:主要用于 api 接口之间消息的传递
YAML 格式:用于配置和管理,YAML 是一种简洁的非标记性语言,内容格式人性化,较易读

YAML 语法格式:
●大小写敏感
●使用缩进表示层级关系
●不支持Tab键制表符缩进,只使用空格缩进
●缩进的空格数目不重要,只要相同层级的元素左侧对齐即可,通常开头缩进两个空格
●符号字符后缩进一个空格,如冒号,逗号,短横杆(-)等
●“---”表示YAML格式,一个文件的开始,用于分隔文件间
●“#”表示注释

kubectl api-versions

admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1								#如果是业务场景一般首选使用 apps/v1
apps/v1beta1						#带有beta字样的代表的是测试版本,不用在生产环境中
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1


#编写一个yaml文件启动nginx
mkdir /mnt/demo
cd /mnt/demo

vim nginx-deployment.yaml

apiVersion: apps/v1   #指定api版本标签
kind: Deployment   #定义资源的类型或者/角色,deployment为副本控制器,此处资源类型可以是Deployment Job Ingress Service等
metadata:    #定义资源的元数据信息,比如资源的名称,namespace,标签等信息
  name: nginx-deployment  #定义资源的名称,在同一个namespace空间中必须是唯一的
  labels:                #定义Deployment资源标签
    app: nginx            
spec:            #定义deployment资源需要的参数属性,诸如是否在容器失败时重新启动容器的属性
  replicas: 3    #定义副本数量
  selector:      #定义标签选择器
    matchLabels: #定义匹配标签
      app: nginx #需与 .spec.templete.metadata.labels 定义的标签保持一致
    spec:
      containers:           #定义容器属性
      - name: nginx         #定义一个容器名,一个 - name: 定义一个容器
        image: nginx:1.15.4 #定义容器使用的镜像以及版本
        ports: 
        - contionerPort: 80  #定义容器对外的端口
        

#创建资源对象
kubectl apply -f nginx-deployment.yaml

#查看创建的pod资源
kubectl get pods -o wide

NAME                                READY   STATUS              RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
nginx-deployment-746ccc65d8-7th2c   0/1     ContainerCreating   0          10s   <none>   node01   <none>           <none>
nginx-deployment-746ccc65d8-8mzjx   0/1     ContainerCreating   0          10s   <none>   node02   <none>           <none>
nginx-deployment-746ccc65d8-mtkmn   0/1     ContainerCreating   0          10s   <none>   node02   <none>           <none>

#创建service服务对外提供访问并测试 #也可以和上面的yaml 文件写在一起,kubectl delete 删除即可,使用 --- 分隔
vim nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    apps: nginx
spec:
  type: NodePort
  ports: 
  - port: 80
    targetPort: 80
  selector:
    app: nginx


#创建资源对象
kubectl create -f nginx-service.yaml

kubectl get svc
NAME            TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.96.0.1    <none>        443/TCP        8d
nginx-service   NodePort    10.96.64.1   <none>        80:32663/TCP   30s

#使用curl访问 192.168.111.7:32663
curl 192.168.111.1:32663



-----------------------------------------------------------------------------------------
详解k8s中的port:
●port
port 是 k8s 集群内部访问service的端口,即通过 clusterIP: port 可以从 Pod 所在的 Node 上访问到 service

●nodePort
nodePort 是外部访问 k8s 集群中 service 的端口,通过 nodeIP: nodePort 可以从外部访问到某个 service。

●targetPort
targetPort 是 Pod 的端口,从 port 或 nodePort 来的流量经过 kube-proxy 反向代理负载均衡转发到后端 Pod 的 targetPort 上,最后进入容器。

●containerPort
containerPort 是 Pod 内部容器的端口,targetPort 映射到 containerPort。
-----------------------------------------------------------------------------------------


#kubectl run --dry-run=client 打印相应的 API 对象而不执行创建
kubectl run nginx-test --image=nginx --port=80 --dry-run=client
kubectl create deployment nginx-deploy --image=nginx --port=80 --replicas=3 --dry-run=cli

  
#查看生成yaml格式
kubectl run nginx-test --image=nginx --port=80 --dry-run=client -o yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx-test
  name: nginx-test
spec:
  containers:
  - image: nginx
    name: nginx-test
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}


kubectl create deployment nginx-deploy --image=nginx --port=80 --replicas=3 --dry-run=client -o yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-deploy
  name: nginx-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-deploy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-deploy
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}


#查看生成json格式
kubectl run nginx-test --image=nginx --port=80 --dry-run=client -o json

{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "nginx-test",
        "creationTimestamp": null,
        "labels": {
            "run": "nginx-test"
        }
    },
    "spec": {
        "containers": [
            {
                "name": "nginx-test",
                "image": "nginx",
                "ports": [
                    {
                        "containerPort": 80
                    }
                ],
                "resources": {}
            }
        ],
        "restartPolicy": "Always",
        "dnsPolicy": "ClusterFirst"
    },
    "status": {}
}


kubectl create deployment nginx-deploy --image=nginx --port=80 --replicas=3 --dry-run=client -o json

{
    "kind": "Deployment",
    "apiVersion": "apps/v1",
    "metadata": {
        "name": "nginx-deploy",
        "creationTimestamp": null,
        "labels": {
            "app": "nginx-deploy"
        }
    },
    "spec": {
        "replicas": 3,
        "selector": {
            "matchLabels": {
                "app": "nginx-deploy"
            }
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "app": "nginx-deploy"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "nginx",
                        "image": "nginx",
                        "ports": [
                            {
                                "containerPort": 80
                            }
                        ],
                        "resources": {}
                    }
                ]
            }
        },
        "strategy": {}
    },
    "status": {}
}

#使用yaml格式导出生成模板,并进行修改以及删除一些不必要的参数
kubectl run nginx-test --image=nginx --port=80 --dry-run=client -o yaml > nginx-test.yaml

kubectl create deployment nginx-deploy --image=nginx --port=80 --replicas=3 --dry-run=client -o yaml  > nginx-deploy.yaml

#以nginx-test.yaml举例
vim nginx-test.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null     #删除
  labels:
    run: nginx-test
  name: nginx-test
spec:
  containers:
  - image: nginx
    name: nginx-test
    ports:
    - containerPort: 80
    resources: {}             #删除
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}                    #删除


#将现有的资源生成模板导出
kubectl get svc nginx-service -o yaml

#保存到文件中
kubectl get svc nginx-service -o yaml > my-svc.yaml

#查看字段帮助信息,可一层层的查看相关资源对象的帮助信息
kubectl explain deployments.spec.template.spec.containers
或
kubectl explain pods.spec.containers


#创建一个yaml文件,创建一个pod,资源名称my-nginx-emmm 命名空间my-emmm 容器镜像nginx-1.14 
#容器端口80 标签abcd:my-emmm 创建service管理上面的pod 修改页面,显示 abc emmm,可以对外访问

vim ns-pod-service.yaml

apiVersion: v1
kind: Namespace
metadata:
  name=my-emmm
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    abcd: emmm
  name: my-nginx-emmm
  namespace: my-emmm
spec:
  containers:
  - image: nginx:1.14
    name: my-nginx-emmm
    ports:
    - containerPort: 80
---
apiVersion: v1    
kind: Service
metadata:
  labels:
    abcd: emmm
  name: my-nginx-emmm
  namespace: my-emmm
spec:
  ports:
  - nodePort: 32000
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    abcd: emmm
  type: NodePort

#导入
kubectl apply -f ns-pod-service.yaml

#查看详细情况
kubectl get pod,svc -n my-emmm -o wide
NAME                READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
pod/my-nginx-emmm   1/1     Running   0          38s   10.244.1.50   node01   <none>           <none>

NAME                    TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR
service/my-nginx-emmm   NodePort   10.96.114.17   <none>        80:32000/TCP   38s   abcd=emmm

#修改主页
kubectl exec -it my-nginx-emmm bash -n my-emmm 

echo abc emmm > /usr/share/nginx/html/index.html


curl 192.168.111.7:32000
abc emmm


外部浏览器访问

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/640173.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

在某云服务器上搭建公网kali linux2.0

前提&#xff1a; 可用的 CVM 实例 挂载一个系统盘之外的盘&#xff0c;安装完成后可卸载&#xff01; 创建实例&#xff0c;安装centos7系统&#xff01; 然后执行fdisk -l看磁盘的情况 在这里我将把镜像写入vdb这块数据盘 非 root 的情况下记得sudo执行以下命令 注意&…

【综合类型第 39 篇】《我的创作纪念日》成为创作者的第2048天

这是【综合类型第 39 篇】&#xff0c;如果觉得有用的话&#xff0c;欢迎关注专栏。 前言 无意间看了一眼CSDN的私信&#xff0c;提示我 Allen Su &#xff0c;不知不觉今天已经是你成为创作者的 第2048天 啦&#xff0c;为了纪念这一天&#xff0c;我们为您准备了一份专属小…

51-53 DriveWorld:通过自动驾驶世界模型进行 4D 预训练场景理解 (含模型数据流梳理)

24年5月&#xff0c;北京大学、国防创新研究院无人系统技术研究中心、中国电信人工智能研究院联合发布了DriveWorld: 4D Pre-trained Scene Understanding via World Models for Autonomous Driving。 DriveWorld在UniAD的基础上又有所成长&#xff0c;提升了自动驾驶目标检测…

Java方法的基本用法

Java方法的基本用法 前言一、什么是方法方法存在的意义示例 二、方法定义语法基本语法代码示例注意事项 三、方法调用的执行过程基本规则代码示例计算两个整数相加计算 1! 2! 3! 4! 5! 四、实参和形参的关系代码示例交换两个整型变量原因分析解决办法 五、没有返回值的方法…

如果有多个文件夹,怎么快速获得文件夹的名字呢

上一篇写到怎么批量建立文件夹&#xff0c;那么怎么获取批量文件夹的名字呢&#xff1f; 一、啊这&#xff0c;这真是一个好问题二、这个得用Python&#xff08;文本末尾有打包程序&#xff0c;点击链接运行就可以了&#xff09;&#xff08;1&#xff09;首先建立一个py文件&a…

类的组合、作用域与可见性、类的静态成员、单例模式、

类的组合 一个类内嵌其他类的对象作为成员的情况 has - a组合 初始化列表的另一用途&#xff1a;为了调用数据成员的带参构造函数 能够层层递进 class Line { public:Line(int x1 0, int y1 0, int x2 0, int y2 0);Line(const Line &other);~Line();Line(const Po…

linux mail命令及其历史

一、【问题描述】 最近隔壁组有人把crontab删了&#xff0c;crontab这个命令有点反人类&#xff0c;它的参数特别容易误操作&#xff1a; crontab - 是删除计划表 crontab -e 是编辑&#xff0c;总之就是特别容易输入错误。 好在可以通过mail命令找回&#xff0c;但是mai…

恭喜!国内医生喜提哈佛大学布莱根妇女医院访问学者邀请函

【校园简介】 布莱根妇女医院(Brigham and Women’s Hospital&#xff0c;BWH)位于马萨诸塞州波士顿的哈佛医学区&#xff0c;毗邻于哈佛医学院校园&#xff0c;是哈佛大学医学院的主要附属医院之一。位于马萨诸塞州波士顿的布莱根妇女医院有12项成人学科位居全国权威,并在耳鼻…

【Linux】详解线程控制之线程创建线程终止线程等待线程分离

一、线程创建 thread&#xff1a;这是一个指向pthread_t类型的指针&#xff0c;用于获取新创建线程的线程ID。在调用pthread_create后&#xff0c;这个指针会被设置为新线程的ID。 attr&#xff1a;这是一个指向pthread_attr_t类型的指针&#xff0c;用于设置线程的属性&#x…

网络工程师备考1——基础学习

认识设备 1 交换机 一、什么是交换机&#xff1f; 实现不同电脑之间数据的转发 换机是一种用于电(光)信号转发的网络设备。 它可以为接入交换机的任意两个网络节点提供独享的电信号通路。最常见的交换机是以太网交换机。交换机工作于OSI参考模型的第二层&#xff0c;即数据…

SpringBoot3整合阿里云短信服务-1(配置阿里云短信服务)

SpringBoot3整合阿里云短信服务-1(配置阿里云短信服务) 一、开通阿里云短信服务 阿里云官网:阿里云官网 选择产品中企业服务与云通信中的短信服务 选择免费开通 选择快速学习和测试 根据这几个全部配置一下我这里是配置好了所以学习进度是100% 1.1 添加资质 首先选择新增资质 …

SpringBoot发送邮箱

一、导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId> </dependency> 二、添加配置 application.yml文件 将username修改为自己的邮箱&#xff0c;password修改为…

【Vue】Vue2使用ElementUI

目录 Element UI介绍特点Vue2使用Element安装引入ElementUI组件库 使用ElementUI用户注册列表展示其他 mint-ui介绍特点安装组件引入组件Mint-ui相关组件 Element UI 介绍 官网(基于 Vue 2.x ):https://element.eleme.cn/#/zh-CN ElementUI 是一个基于 Vue.js 的桌面端组件库…

基于Arduino的电梯超载报警系统

企鹅&#xff1a;2583550535 项目和论文都有 第1章 绪论.............................................................................................................................. 1 1.1 项目背景及意义........................................................…

ABP.VNET 项目结构

想要了解ABP分层架构&#xff1a;ABP分层架构-CSDN博客 可以看此篇文章 apb.vnet 生成的项目的目录结构 .Application 项目 应用服务用于将领域(业务)逻辑暴露给展现层。 展现层通过传入DTO(数据传输对象)参数来调用应用服务&#xff0c;而应用服务通过领域对象来执行相应的…

【网络安全】2030年十大新兴网络安全威胁

欧盟网络安全局&#xff08;ENISA&#xff09;已发布了一份全面的清单&#xff0c;列出了预计到2030年将影响数字领域的十大新兴网络安全威胁。 该预测是为期八个月的广泛研究的成果&#xff0c;融合了ENISA前瞻专家小组、CSIRTs网络以及欧盟CyCLONe专家的见解。 这项研究突显…

抖音小店无货源怎么做?从开店到发货,最全教程来了!

哈喽~我是电商月月 近几年&#xff0c;抖音的发展如火如荼&#xff0c;抖音小店也吸引了大批新手商家入驻 那抖音小店具体流程到底怎么做&#xff1f;无货源的商家去哪找货&#xff1f;怎么上架&#xff0c;如何推流? 不知道&#xff1f; 今天我就给大家讲一下抖音小店从开…

[集群聊天服务器]----(五)User类、UserModel类

接着上文[集群聊天服务器]----(四)MySQL数据库模块&#xff0c;接下来我们对User类、UserModel类进行剖析&#xff0c;User表和UserModel类是项目最基本也是最重要的部分&#xff0c;通过它我们对用户的id&#xff0c;用户名&#xff0c;密码&#xff0c;状态相关信息进行存储&…

数据分析【方差分析】四

方差分析的核心 什么是方差分析:方差分析是假设检验的一种延续与扩展,主要用于多个总体均值(三组或三组以上均值)是否相等做出假设检验,研究分类型自变量对数值型因变量的影响。 它的零假设和设备假设分别为: 单因素方差分析的前提条件 独立性 组内独立(随机抽样、…

<string.h>中部分库函数的模拟实现

前言 嗨&#xff0c;我是firdawn&#xff0c;本章将简单介绍&#xff0c;<string.h>中部分库函数的模拟实现&#xff0c;如strncpy&#xff0c;strncat&#xff0c;memcpy&#xff0c;memmove。在本文片末&#xff0c;还讲简单介绍判断机器大小端的函数实现&#xff0c;…