Kubernetes资源详解
华子目录
- 1.Kubernetes中的资源
- 1.1资源管理介绍
- 1.2资源管理方式
- 1.2.1命令式对象管理
- 1.2.2`kubectl`常见`command`命令
- 1.2.3资源类型
- 1.2.4常用资源类型
- `基本命令`示例
- `运行和调试`命令示例
- `高级命令`示例
- 总结
- `其他命令`示例
- `create`和`apply`区别案例
- 显示`命名空间`
- 查看`命名空间`中的`pod`
- 如何对外`暴露端口`
- 查看`某一个pod`的详细信息
1.Kubernetes中的资源
1.1资源管理介绍

- 在
kubernetes中,所有的内容都抽象为资源,用户需要通过操作资源来管理kubernetes kubernetes本质上就是一个集群系统,用户可以在集群中部署各种服务- 所谓的
部署服务,其实就是在kubernetes集群中运行一个个的容器,并将指定的程序跑在容器中 kubernetes的最小管理单元是pod而不是容器,只能将容器放在pod中kubernetes一般也不会直接管理pod,而是通过pod控制器来管理pod的pod中容器服务的访问是由kubernetes提供的service资源来实现的。pod中的容器不能直接被访问,需要通过service微服务对端口进行暴露,最终我们通过微服务来访问pod中的容器pod中程序的数据需要持久化是由kubernetes提供的各种存储系统来实现的
1.2资源管理方式
命令式对象管理:直接使用命令去操作kubernetes资源
[root@k8s-master ~]# kubectl run nginx-pod --image=nginx:latest --port=80#nginx-pod是pod名
命令式对象配置:通过命令配置和配置文件去操作kubernetes资源- 不能对
yaml中的内容做更新(k8s不允许对create创建的yaml文件进行修改)
- 不能对
[root@k8s-master ~]# kubectl create/patch -f nginx-pod.yml
声明式对象配置:通过apply命令和配置文件去操作kubernetes资源- 可以对
yaml中的内容做更新(修改完yaml文件的内容后,可以使用apply对其进行应用)
- 可以对
[root@k8s-master ~]# kubectl apply -f nginx-pod.yml
| 类型 | 适用环境 | 优点 | 缺点 |
|---|---|---|---|
| 命令式对象管理 | 测试 | 简单 | 只能操作活动对象,无法审计,跟踪 |
| 命令式对象配置 | 开发 | 可以审计,跟踪 | 项目大时,配置文件多,操作麻烦 |
| 声明式对象配置 | 开发 | 支持目录操作 | 意外情况下难以调试 |
1.2.1命令式对象管理
kubectl是kubernetes集群的命令行工具,通过它能够对集群本身进行管理,并能够在集群上进行容器化应用的安装部署kubectl命令的语法如下:
[root@k8s-master ~]# kubectl [command] [type] [name] [flags]
command:指定要对资源执行的操作,例如create、get、deletetype:指定资源类型,比如deployment、pod、servicename:指定资源名称,名称大小写敏感flags:指定额外的可选参数
查看所有pod
[root@k8s-master ~]# kubectl get pods
查看某一个pod
[root@k8s-master ~]# kubectl get pods pod名
查看某个pod,以yaml格式显示
[root@k8s-master ~]# kubectl get pods pod名 -o yaml
创建两个名为webserver1和webserver2的pod
- 其中
myapp是一个nginx服务
[root@k8s-master ~]# kubectl run webserver1 --image myapp:v1
pod/webserver1 created
[root@k8s-master ~]# kubectl run webserver2 --image myapp:v2
pod/webserver2 created[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
webserver1 1/1 Running 0 8m27s
webserver2 1/1 Running 0 6m37s[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webserver1 1/1 Running 0 2m 10.244.1.2 k8s-node1.org <none> <none>
webserver2 1/1 Running 0 10s 10.244.2.6 k8s-node2.org <none> <none>[root@k8s-master ~]# kubectl get pods -o name
pod/webserver1
pod/webserver2
1.2.2kubectl常见command命令
| 命令分类 | 命令 | 翻译 | 命令作用 |
|---|---|---|---|
基本命令 | create | 创建 | 创建一个资源 |
edit | 编辑 | 编辑一个资源 | |
get | 获取 | 获取一个资源 | |
patch | 补丁更新 | 更新一个资源 | |
delete | 删除 | 删除一个资源 | |
explain | 解释 | 展示资源文档 | |
运行和调试 | run | 运行 | 在集群中运行一个指定的镜像 |
expose | 暴露 | 暴露资源为service | |
describe | 描述 | 显示资源内部信息 | |
logs | 日志 | 输出容器在pod中的日志 | |
attach | 缠绕 | 进入运行中的容器 | |
exec | 执行 | 执行容器中的一个命令 | |
cp | 复制 | 在pod内外复制文件 | |
rollout | 首次展示 | 管理资源的发布 | |
scale | 规模 | 扩(缩)容pod的数量 | |
autoscale | 自动调整 | 自动调整pod的数量 | |
高级命令 | apply | 应用 | 通过文件对资源进行配置 |
label | 标签 | 更新资源上的标签 | |
其他命令 | cluster-info | 集群信息 | 显示集群信息 |
version | 版本 | 显示当前server和client的版本 |
1.2.3资源类型
kubernetes中所有的内容都抽象为资源
- 查看
所有资源类型
[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
namespaces ns v1 false Namespace
nodes no v1 false Node
persistentvolumeclaims pvc v1 true PersistentVolumeClaim
persistentvolumes pv v1 false PersistentVolume
pods po v1 true Pod
podtemplates v1 true PodTemplate
replicationcontrollers rc v1 true ReplicationController
resourcequotas quota v1 true ResourceQuota
secrets v1 true Secret
serviceaccounts sa v1 true ServiceAccount
services svc v1 true Service
mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration
validatingadmissionpolicies admissionregistration.k8s.io/v1 false ValidatingAdmissionPolicy
validatingadmissionpolicybindings admissionregistration.k8s.io/v1 false ValidatingAdmissionPolicyBinding
validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition
apiservices apiregistration.k8s.io/v1 false APIService
controllerrevisions apps/v1 true ControllerRevision
daemonsets ds apps/v1 true DaemonSet
deployments deploy apps/v1 true Deployment
replicasets rs apps/v1 true ReplicaSet
statefulsets sts apps/v1 true StatefulSet
selfsubjectreviews authentication.k8s.io/v1 false SelfSubjectReview
tokenreviews authentication.k8s.io/v1 false TokenReview
localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling/v2 true HorizontalPodAutoscaler
cronjobs cj batch/v1 true CronJob
jobs batch/v1 true Job
certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest
leases coordination.k8s.io/v1 true Lease
endpointslices discovery.k8s.io/v1 true EndpointSlice
events ev events.k8s.io/v1 true Event
flowschemas flowcontrol.apiserver.k8s.io/v1 false FlowSchema
prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1 false PriorityLevelConfiguration
ingressclasses networking.k8s.io/v1 false IngressClass
ingresses ing networking.k8s.io/v1 true Ingress
networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy
runtimeclasses node.k8s.io/v1 false RuntimeClass
poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget
clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io/v1 false ClusterRole
rolebindings rbac.authorization.k8s.io/v1 true RoleBinding
roles rbac.authorization.k8s.io/v1 true Role
priorityclasses pc scheduling.k8s.io/v1 false PriorityClass
csidrivers storage.k8s.io/v1 false CSIDriver
csinodes storage.k8s.io/v1 false CSINode
csistoragecapacities storage.k8s.io/v1 true CSIStorageCapacity
storageclasses sc storage.k8s.io/v1 false StorageClass
volumeattachments storage.k8s.io/v1 false VolumeAttachment
1.2.4常用资源类型
| 资源分类 | 资源名称 | 缩写 | 资源作用 |
|---|---|---|---|
集群级别资源 | nodes | no | 集群组成部分 |
namespaces | ns | 隔离pod | |
pod资源 | pods | po | 装载容器 |
pod资源控制器 | replicationcontrollers | rc | 控制pod资源 |
replicasets | rs | 控制pod资源 | |
deployments | deploy | 控制pod资源 | |
daemonsets | ds | 控制pod资源 | |
jobs | 控制pod资源 | ||
cronjobs | cj | 控制pod资源 | |
horizontalpodautoscalers | hpa | 控制pod资源 | |
statefulsets | sts | 控制pod资源 | |
服务发现资源 | services | svc | 统一pod对外接口 |
ingress | ing | 统一pod对外接口 | |
存储资源 | volumeattachments | 存储 | |
persistentvolumes | pv | 存储 | |
persistentvolumeclaims | pvc | 存储 | |
配置资源 | configmaps | cm | 配置 |
secrets | 配置 |
基本命令示例
kubectl的详细说明地址:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
- 显示集群版本
[root@k8s-master ~]# kubectl version
Client Version: v1.30.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0
- 显示集群信息
[root@k8s-master ~]# kubectl cluster-info
Kubernetes control plane is running at https://172.25.254.100:6443
CoreDNS is running at https://172.25.254.100:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
- 创建一个名为
webcluster的deployment控制器,控制器中pod数量为2
#先删除之前的pod
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATE
webserver1 1/1 Running 0 16h 10.244.1.2 k8s-node1.org <none>
webserver2 1/1 Running 0 16h 10.244.2.6 k8s-node2.org <none>[root@k8s-master ~]# kubectl delete pods webserver1 --force
[root@k8s-master ~]# kubectl delete pods webserver2 --force[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
#创建一个名为`webcluster`的`deployment`控制器,控制器中`pod`数量为`2`
[root@k8s-master ~]# kubectl create deployment webcluster --image nginx --replicas 2
deployment.apps/webcluster created[root@k8s-master ~]# kubectl get pods -o name
pod/webcluster-7c584f774b-9b67l
pod/webcluster-7c584f774b-d8xws[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webcluster-7c584f774b-9b67l 1/1 Running 0 79s 10.244.2.7 k8s-node2.org <none> <none>
webcluster-7c584f774b-d8xws 1/1 Running 0 79s 10.244.1.3 k8s-node1.org <none> <none>#查看deployment控制器
[root@k8s-master ~]# kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
webcluster 2/2 2 2 50s
- 查看资源帮助
explain
#等级式查看
[root@k8s-master ~]# kubectl explain deployment
GROUP: apps
KIND: Deployment
VERSION: v1DESCRIPTION:Deployment enables declarative updates for Pods and ReplicaSets.FIELDS:apiVersion <string>APIVersion defines the versioned schema of this representation of an object.Servers should convert recognized schemas to the latest internal value, andmay reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resourceskind <string>Kind is a string value representing the REST resource this objectrepresents. Servers may infer this from the endpoint the client submitsrequests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kindsmetadata <ObjectMeta>Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadataspec <DeploymentSpec>Specification of the desired behavior of the Deployment.status <DeploymentStatus>Most recently observed status of the Deployment.[root@k8s-master ~]# kubectl explain deployment.metadata[root@k8s-master ~]# kubectl explain deployment.spec
- 编辑名为
webcluster的deployment控制器,将pod数量改为3
#编辑名为webcluster的deployment控制器
[root@k8s-master ~]# kubectl edit deployments.apps webcluster
#会进入编辑状态
apiVersion: apps/v1
kind: Deployment
metadata:annotations:deployment.kubernetes.io/revision: "1"creationTimestamp: "2024-10-05T03:47:39Z"generation: 1labels:app: webclustername: webclusternamespace: defaultresourceVersion: "27001"uid: a8bf27c5-c6bb-46d4-b4f7-4accfbb60e71
spec:progressDeadlineSeconds: 600replicas: 3 #将原来的2个pod改为3个pod
......
......
......
:wq
- 发现改完
立即生效
[root@k8s-master ~]# kubectl get deployments.apps webcluster
NAME READY UP-TO-DATE AVAILABLE AGE
webcluster 3/3 3 3 18m[root@k8s-master ~]# kubectl get pods -o name
pod/webcluster-7c584f774b-9b67l
pod/webcluster-7c584f774b-d8xws
pod/webcluster-7c584f774b-r48fd[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webcluster-7c584f774b-9b67l 1/1 Running 0 20m 10.244.2.7 k8s-node2.org <none> <none>
webcluster-7c584f774b-d8xws 1/1 Running 0 20m 10.244.1.3 k8s-node1.org <none> <none>
webcluster-7c584f774b-r48fd 1/1 Running 0 114s 10.244.2.8 k8s-node2.org <none> <none>
- 利用
补丁 patch更改控制器配置(编辑名为webcluster的deployment控制器,将pod数量改为4)
[root@k8s-master ~]# kubectl patch deployments.apps webcluster -p '{"spec":{"replicas":4}}'
deployment.apps/webcluster patched[root@k8s-master ~]# kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
webcluster 4/4 4 4 26m[root@k8s-master ~]# kubectl get pods -o name
pod/webcluster-7c584f774b-9b67l
pod/webcluster-7c584f774b-d8xws
pod/webcluster-7c584f774b-r48fd
pod/webcluster-7c584f774b-swst6[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webcluster-7c584f774b-9b67l 1/1 Running 0 27m 10.244.2.7 k8s-node2.org <none> <none>
webcluster-7c584f774b-d8xws 1/1 Running 0 27m 10.244.1.3 k8s-node1.org <none> <none>
webcluster-7c584f774b-r48fd 1/1 Running 0 9m7s 10.244.2.8 k8s-node2.org <none> <none>
webcluster-7c584f774b-swst6 1/1 Running 0 92s 10.244.1.4 k8s-node1.org <none> <none>
- 在
控制器中删除pod
在控制器中删除一个pod后,k8s会根据数量再开一个pod
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webcluster-7c584f774b-9b67l 1/1 Running 0 27m 10.244.2.7 k8s-node2.org <none> <none>
webcluster-7c584f774b-d8xws 1/1 Running 0 27m 10.244.1.3 k8s-node1.org <none> <none>
webcluster-7c584f774b-r48fd 1/1 Running 0 9m7s 10.244.2.8 k8s-node2.org <none> <none>
webcluster-7c584f774b-swst6 1/1 Running 0 92s 10.244.1.4 k8s-node1.org <none> <none>
[root@k8s-master ~]# kubectl delete pods webcluster-7c584f774b-9b67l
pod "webcluster-7c584f774b-9b67l" deleted
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webcluster-7c584f774b-d8xws 1/1 Running 0 31m 10.244.1.3 k8s-node1.org <none> <none>
webcluster-7c584f774b-r48fd 1/1 Running 0 13m 10.244.2.8 k8s-node2.org <none> <none>
webcluster-7c584f774b-swst6 1/1 Running 0 5m25s 10.244.1.4 k8s-node1.org <none> <none>
webcluster-7c584f774b-tx55p 1/1 Running 0 5s 10.244.2.9 k8s-node2.org <none> <none>
- 直接删除
控制器,控制器控制的所有pod都会被删除
[root@k8s-master ~]# kubectl delete deployments.apps webcluster
deployment.apps "webcluster" deleted[root@k8s-master ~]# kubectl get deployments.apps
No resources found in default namespace.[root@k8s-master ~]# kubectl get pods -o wide
No resources found in default namespace.
运行和调试命令示例
- 首先要保证一个
纯净的实验环境
#发现没有pod
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
- 运行一个名为
testpod的pod,该pod不属于任何控制器
[root@k8s-master ~]# kubectl run testpod --image nginx
pod/testpod created[root@k8s-master ~]# kubectl get pods -o name
pod/testpod[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod 1/1 Running 0 9s 10.244.2.10 k8s-node2.org <none> <none>
端口暴露
[root@k8s-master ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18h#--port指定pod中的端口,--target-port指定容器中的服务端口
[root@k8s-master ~]# kubectl expose pod testpod --port 8080 --target-port 80
service/testpod exposed[root@k8s-master ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18h
testpod ClusterIP 10.99.119.189 <none> 8080/TCP 8s
#访问10.244.2.12
[root@k8s-master ~]# curl 10.244.2.12
<!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>#访问10.99.119.189:8080
[root@k8s-master ~]# curl 10.99.119.189: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>
- 查看
运行中pod的详细信息
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod 1/1 Running 0 10m 10.244.2.12 k8s-node2.org <none> <none>[root@k8s-master ~]# kubectl describe pods testpod
Name: testpod
Namespace: default
Priority: 0
Service Account: default
Node: k8s-node2.org/172.25.254.20
Start Time: Sat, 05 Oct 2024 00:45:53 -0400
Labels: run=testpod
Annotations: <none>
Status: Running
IP: 10.244.2.12
IPs:IP: 10.244.2.12
Containers:testpod:Container ID: docker://13361a3a29b394fa0049c28405a76a686a26a7c9a1e1fddbcdc4312f2698156aImage: nginxImage ID: docker-pullable://nginx@sha256:127262f8c4c716652d0e7863bba3b8c45bc9214a57d13786c854272102f7c945Port: <none>Host Port: <none>State: RunningStarted: Sat, 05 Oct 2024 00:45:54 -0400Ready: TrueRestart Count: 0Environment: <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-tzfw6 (ro)
Conditions:Type StatusPodReadyToStartContainers TrueInitialized TrueReady TrueContainersReady TruePodScheduled True
Volumes:kube-api-access-tzfw6:Type: Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds: 3607ConfigMapName: kube-root-ca.crtConfigMapOptional: <nil>DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Scheduled 10m default-scheduler Successfully assigned default/testpod to k8s-node2.orgNormal Pulling 10m kubelet Pulling image "nginx"Normal Pulled 10m kubelet Successfully pulled image "nginx" in 281ms (281ms including waiting). Image size: 187694648 bytes.Normal Created 10m kubelet Created container testpodNormal Started 10m kubelet Started container testpod
- 查看资源
日志
[root@k8s-master ~]# kubectl logs
daemonsets/ pods/ services/
deployments/ replicasets/ statefulsets/
jobs/ replicationcontrollers/ testpod
[root@k8s-master ~]# kubectl logs pods/testpod
......
......
......
- 运行交互
pod
[root@k8s-master ~]# kubectl run -it testpod1 --image busybox
If you don't see a command prompt, try pressing enter.
/ #
/ #
/ # ls
bin dev etc home lib lib64 proc root sys tmp usr var
/ # exit #退出交互式,不停止pod[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod 1/1 Running 0 20m 10.244.2.12 k8s-node2.org <none> <none>
testpod1 1/1 Running 1 (24s ago) 36s 10.244.1.6 k8s-node1.org <none> <none>#再次进入容器
[root@k8s-master ~]# kubectl attach -it pods/testpod1
If you don't see a command prompt, try pressing enter.
/ #
/ #
/ # ls
bin dev etc home lib lib64 proc root sys tmp usr var
/ # exit 或 ctrl+p+q退出不停止pod[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod 1/1 Running 0 24m 10.244.2.12 k8s-node2.org <none> <none>
testpod1 1/1 Running 2 (3m9s ago) 4m30s 10.244.1.6 k8s-node1.org <none> <none>
- 在已经运行的
pod中运行容器中的指定命令
[root@k8s-master ~]# kubectl exec -it pods/testpod1 ifconfig
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
eth0 Link encap:Ethernet HWaddr 12:C1:23:80:08:BAinet addr:10.244.1.6 Bcast:10.244.1.255 Mask:255.255.255.0inet6 addr: fe80::10c1:23ff:fe80:8ba/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1RX packets:15 errors:0 dropped:0 overruns:0 frame:0TX packets:13 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:2148 (2.0 KiB) TX bytes:962 (962.0 B)lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- 复制
master宿主机文件到pod中的容器中
[root@k8s-master ~]# kubectl cp anaconda-ks.cfg testpod1:/[root@k8s-master ~]# kubectl exec -it pods/testpod1 /bin/sh
/ # ls
anaconda-ks.cfg home root var
bin lib sys
dev lib64 tmp
etc proc usr
/ # touch file1
/ # ls
anaconda-ks.cfg file1 proc usr
bin home root var
dev lib sys
etc lib64 tmp
/ # echo hello world > file1
/ # cat file1
hello world111
- 复制
pod容器中的文件到master宿主机中
[root@k8s-master ~]# kubectl cp testpod1:/file1 /mnt/file
tar: removing leading '/' from member names
[root@k8s-master ~]# cd /mnt/
[root@k8s-master mnt]# ls
file
[root@k8s-master mnt]# cat file
hello world111
高级命令示例
- 利用
命令生成yaml格式的文件
[root@k8s-master ~]# mkdir huazi
[root@k8s-master ~]# cd huazi/
[root@k8s-master huazi]#
首先要确保一个纯净的实验环境
[root@k8s-master huazi]# kubectl get pods
NAME READY STATUS RESTARTS AGE
testpod 1/1 Running 0 43m
testpod1 1/1 Running 2 (22m ago) 23m[root@k8s-master huazi]# kubectl delete pods testpod
pod "testpod" deleted
[root@k8s-master huazi]# kubectl delete pods testpod1 --force
pod "testpod1" deleted
--drg-run=client仅尝试不运行,是一个固定写法
#仅尝试,不运行
[root@k8s-master huazi]# kubectl create deployment webserver --image nginx --dry-run=client -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: webservername: webserver
spec:replicas: 1selector:matchLabels:app: webserverstrategy: {}template:metadata:creationTimestamp: nulllabels:app: webserverspec:containers:- image: nginxname: nginxresources: {}
status: {}
导入文件
#创建一个控制器文件
[root@k8s-master huazi]# kubectl create deployment webserver --image nginx --dry-run=client -o yaml > webserver.yml
[root@k8s-master huazi]# ls
webserver.yml
#对文件进行简单的修改
[root@k8s-master huazi]# vim webserver.yml
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: webservername: webserver
spec:replicas: 2 #修改为2个podselector:matchLabels:app: webservertemplate:metadata:labels:app: webserverspec:containers:- image: nginxname: nginx
应用文件
#这个文件是一个控制器文件
[root@k8s-master huazi]# kubectl apply -f webserver.yml
deployment.apps/webserver created[root@k8s-master huazi]# kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
webserver 2/2 2 2 27s[root@k8s-master huazi]# kubectl get pods -o name
pod/webserver-7bc769cd4c-mg9kl
pod/webserver-7bc769cd4c-nl7q2[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webserver-7bc769cd4c-mg9kl 1/1 Running 0 2m10s 10.244.2.13 k8s-node2.org <none> <none>
webserver-7bc769cd4c-nl7q2 1/1 Running 0 2m10s 10.244.1.7 k8s-node1.org <none> <none>
- 删除
控制器文件
[root@k8s-master huazi]# kubectl delete -f webserver.yml
deployment.apps "webserver" deleted[root@k8s-master huazi]# kubectl get deployments.apps
No resources found in default namespace.[root@k8s-master huazi]# kubectl get pods -o wide
No resources found in default namespace.
- 管理资源
标签
#这个是没有控制的pod
[root@k8s-master huazi]# kubectl run webserver --image nginx
pod/webserver created[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webserver 1/1 Running 0 12s 10.244.2.15 k8s-node2.org <none> <none>[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver 1/1 Running 0 50s run=webserver
- 更改标签
--overwrite覆盖
[root@k8s-master huazi]# kubectl label pods webserver run=web --overwrite
pod/webserver labeled[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver 1/1 Running 0 3m48s run=web
- 添加标签
- 通过
键值对添加即可
[root@k8s-master huazi]# kubectl label pods webserver app=web1
pod/webserver labeled[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver 1/1 Running 0 5m33s app=web1,run=web
删除标签
[root@k8s-master huazi]# kubectl label pods webserver app-
pod/webserver unlabeled[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver 1/1 Running 0 6m48s run=web
- 创建一个
控制器pod
#先删除之前的pod
[root@k8s-master huazi]# kubectl delete pods webserver
pod "webserver" deleted
[root@k8s-master huazi]# kubectl get pods
No resources found in default namespace.
[root@k8s-master huazi]# kubectl create deployment webserver --image nginx --dry-run=client -o yaml > web-label.yaml
[root@k8s-master huazi]# ls
web-label.yaml webserver.yml[root@k8s-master huazi]# vim web-label.yaml
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: webservername: webserver
spec:replicas: 2 #修改为2个podselector:matchLabels:app: webservertemplate:metadata:labels:app: webserverspec:containers:- image: nginxname: nginx
[root@k8s-master huazi]# kubectl apply -f web-label.yaml
deployment.apps/webserver created[root@k8s-master huazi]# kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
webserver 2/2 2 2 7s[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver-7bc769cd4c-bnklx 1/1 Running 0 44s app=webserver,pod-template-hash=7bc769cd4c
webserver-7bc769cd4c-cdj8f 1/1 Running 0 44s app=webserver,pod-template-hash=7bc769cd4c
修改一个控制器pod上的一个标签
[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver-7bc769cd4c-bnklx 1/1 Running 0 44s app=webserver,pod-tem plate-hash=7bc769cd4c
webserver-7bc769cd4c-cdj8f 1/1 Running 0 44s app=webserver,pod-tem plate-hash=7bc769cd4c[root@k8s-master huazi]# kubectl label pods webserver-7bc769cd4c-bnklx app=lee --over write
pod/webserver-7bc769cd4c-bnklx labeled
[root@k8s-master huazi]# kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS
webserver-7bc769cd4c-bnklx 1/1 Running 0 3m14s app=lee,pod-templat e-hash=7bc769cd4c
webserver-7bc769cd4c-cdj8f 1/1 Running 0 3m14s app=webserver,pod-t emplate-hash=7bc769cd4c
webserver-7bc769cd4c-cgzcq 1/1 Running 0 3s app=webserver,pod-t emplate-hash=7bc769cd4c
我们发现k8s又起了一个新的pod
当我们删除另一个标签后,k8s又起了一个新的pod
[root@k8s-master huazi]# kubectl label pods webserver-7bc769cd4c-cdj8f pod-template-hash-
pod/webserver-7bc769cd4c-cdj8f unlabeled
[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver-7bc769cd4c-bnklx 1/1 Running 0 5m22s app=lee,pod-template-hash=7bc769cd4c
webserver-7bc769cd4c-cdj8f 1/1 Running 0 5m22s app=webserver
webserver-7bc769cd4c-cgzcq 1/1 Running 0 2m11s app=webserver,pod-template-hash=7bc769cd4c
webserver-7bc769cd4c-zq5mw 1/1 Running 0 5s app=webserver,pod-template-hash=7bc769cd4c
当我们修改回来原来的标签后,k8s又把之前新的pod删除了
[root@k8s-master huazi]# kubectl label pods webserver-7bc769cd4c-bnklx app=webserver --overwrite
pod/webserver-7bc769cd4c-bnklx labeled
[root@k8s-master huazi]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver-7bc769cd4c-cdj8f 1/1 Running 0 8m45s app=webserver
webserver-7bc769cd4c-cgzcq 1/1 Running 0 5m34s app=webserver,pod-template-hash=7bc769cd4c
webserver-7bc769cd4c-zq5mw 1/1 Running 0 3m28s app=webserver,pod-template-hash=7bc769cd4c
总结
所以我们发现,k8s是通过标签去记录pod的数量,如果有多个标签,且多个标签必须一致。如果不一致,则k8s会根据pod的数量重新启动相应个pod
其他命令示例
[root@k8s-master huazi]# kubectl cluster-info
Kubernetes control plane is running at https://172.25.254.100:6443
CoreDNS is running at https://172.25.254.100:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@k8s-master huazi]# kubectl version
Client Version: v1.30.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0
create和apply区别案例
[root@k8s-master huazi]# kubectl run testpod1 --image myapp:v1 --dry-run=client -o yaml > testpod1.yml[root@k8s-master huazi]# ls
testpod1.yml[root@k8s-master huazi]# vim testpod1.yml
apiVersion: v1
kind: Pod
metadata:labels:run: testpod1name: testpod1
spec:containers:- image: myapp:v1name: testpod1[root@k8s-master huazi]# kubectl create -f testpod1.yml
pod/testpod1 created
[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod1 1/1 Running 0 8s 10.244.1.10 k8s-node1.org <none> <none>[root@k8s-master huazi]# curl 10.244.1.10
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>[root@k8s-master huazi]# vim testpod1.yml
apiVersion: v1
kind: Pod
metadata:labels:run: testpod1name: testpod1
spec:containers:- image: myapp:v2 #将版本改为v2name: testpod1#发现使用create更新不了
[root@k8s-master huazi]# kubectl create -f testpod1.yml
Error from server (AlreadyExists): error when creating "testpod1.yml": pods "testpod1" already exists#使用apply可以更新
[root@k8s-master huazi]# kubectl apply -f testpod1.yml[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod1 1/1 Running 1 (23s ago) 3m13s 10.244.1.10 k8s-node1.org <none> <none>[root@k8s-master huazi]# curl 10.244.1.10
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
- 所以
create只能建立,不能更新,apply可以更新
显示命名空间
[root@k8s-master huazi]# kubectl -n
default kube-node-lease kube-system
kube-flannel kube-public
查看命名空间中的pod
- 查看
所有命名空间中的pod --all-namespaces
[root@k8s-master huazi]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default testpod1 1/1 Running 1 (4m54s ago) 7m44s
kube-flannel kube-flannel-ds-m7ksl 1/1 Running 0 22h
kube-flannel kube-flannel-ds-q55gr 1/1 Running 0 22h
kube-flannel kube-flannel-ds-twvv4 1/1 Running 1 (21h ago) 22h
kube-system coredns-6c7f6478d8-gplcq 1/1 Running 0 23h
kube-system coredns-6c7f6478d8-vcqg9 1/1 Running 0 23h
kube-system etcd-k8s-master.org 1/1 Running 0 23h
kube-system kube-apiserver-k8s-master.org 1/1 Running 0 23h
kube-system kube-controller-manager-k8s-master.org 1/1 Running 0 23h
kube-system kube-proxy-2dbz2 1/1 Running 1 (21h ago) 22h
kube-system kube-proxy-fcnpc 1/1 Running 0 23h
kube-system kube-proxy-jwn8w 1/1 Running 0 22h
kube-system kube-scheduler-k8s-master.org 1/1 Running 0 23h
- 查看
默认命名空间中的pod
[root@k8s-master huazi]# kubectl get pods
NAME READY STATUS RESTARTS AGE
testpod1 1/1 Running 1 (7m4s ago) 9m54s
[root@k8s-master huazi]# kubectl -n
default kube-node-lease kube-system
kube-flannel kube-public
[root@k8s-master huazi]# kubectl -n default get pods
NAME READY STATUS RESTARTS AGE
testpod1 1/1 Running 1 (7m58s ago) 10m
如何对外暴露端口
[root@k8s-master huazi]# kubectl run web --image myapp:v1
pod/web created[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
web 1/1 Running 0 32s 10.244.1.11 k8s-node1.org <none> <none>
#10.244.1.11是pod的ip地址[root@k8s-master huazi]# curl 10.244.1.11
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
[root@k8s-master huazi]# kubectl expose pod web --port 8080 --target-port 80
service/web exposed
#--port指定pod中的端口,
#--target-port指定容器中的服务端口[root@k8s-master huazi]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h
web ClusterIP 10.108.123.93 <none> 8080/TCP 19s
#10.108.123.93这个ip是service的ip地址
#当访问10.108.123.93:8080端口时,转到10.244.1.11的80端口[root@k8s-master huazi]# curl 10.108.123.93:8080
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
[root@k8s-master huazi]# kubectl edit services web
apiVersion: v1
kind: Service
metadata:creationTimestamp: "2024-10-05T09:21:02Z"labels:run: webname: webnamespace: defaultresourceVersion: "57432"uid: 33ea0201-e8b2-42ea-874d-2aa2b8e20455
spec:clusterIP: 10.108.123.93clusterIPs:- 10.108.123.93internalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackports:- port: 8080protocol: TCPtargetPort: 80selector:run: websessionAffinity: Nonetype: NodePort #修改类型为NodePort
status:loadBalancer: {}[root@k8s-master huazi]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h
web NodePort 10.108.123.93 <none> 8080:31340/TCP 9m51s[root@k8s-master huazi]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
web 1/1 Running 0 14m 10.244.1.11 k8s-node1.org <none> <none>[root@k8s-master huazi]# curl k8s-node1.org:31340
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>[root@k8s-master huazi]# curl 172.25.254.10:31340
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

发现可以对外访问
[root@k8s-master huazi]# kubectl explain service.spec
......
......
......Possible enum values:- `"ClusterIP"` means a service will only be accessible inside the cluster,via the cluster IP.- `"ExternalName"` means a service consists of only a reference to anexternal name that kubedns or equivalent will return as a CNAME record, withno exposing or proxying of any pods involved.- `"LoadBalancer"` means a service will be exposed via an external loadbalancer (if the cloud provider supports it), in addition to 'NodePort'type.- `"NodePort"` means a service will be exposed on one port of every node,in addition to 'ClusterIP' type.
查看某一个pod的详细信息
[root@k8s-master huazi]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web 1/1 Running 0 20m
[root@k8s-master huazi]# kubectl describe pods web
Name: web
Namespace: default
Priority: 0
Service Account: default
Node: k8s-node1.org/172.25.254.10
Start Time: Sat, 05 Oct 2024 05:17:53 -0400
Labels: run=web
Annotations: <none>
Status: Running
IP: 10.244.1.11
IPs:IP: 10.244.1.11
Containers:web:Container ID: docker://d1f4ea79ffe996f292f2b0af787afdf7e235496b4b4a89878005a3fed662426fImage: myapp:v1Image ID: docker-pullable://myapp@sha256:9eeca44ba2d410e54fccc54cbe9c021802aa8b9836a0bcf3d3229354e4c8870ePort: <none>Host Port: <none>State: RunningStarted: Sat, 05 Oct 2024 05:17:54 -0400Ready: TrueRestart Count: 0Environment: <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-mv6b4 (ro)
Conditions:Type StatusPodReadyToStartContainers TrueInitialized TrueReady TrueContainersReady TruePodScheduled True
Volumes:kube-api-access-mv6b4:Type: Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds: 3607ConfigMapName: kube-root-ca.crtConfigMapOptional: <nil>DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Scheduled 20m default-scheduler Successfully assigned default/web to k8s-node1.orgNormal Pulled 20m kubelet Container image "myapp:v1" already present on machineNormal Created 20m kubelet Created container webNormal Started 20m kubelet Started container web
相关文章:
Kubernetes资源详解
华子目录 1.Kubernetes中的资源1.1资源管理介绍1.2资源管理方式1.2.1命令式对象管理1.2.2kubectl常见command命令1.2.3资源类型1.2.4常用资源类型 基本命令示例运行和调试命令示例高级命令示例总结 其他命令示例create和apply区别案例显示命名空间查看命名空间中的pod如何对外暴…...
C++11之线程
编译环境:Qt join:阻塞当前线程,直到线程函数退出 detach:将线程对象与线程函数分离,线程不依赖线程对象管理 注:join和detach两者必选其一,否则线程对象的回收会影响线程的回收,导致…...
界星空科技漆包线行业称重系统
万界星空科技为漆包线行业提供的称重系统是其MES制造执行系统解决方案中的一个重要组成部分。以下是对该系统的详细介绍: 一、系统概述 万界星空科技漆包线行业称重系统,是集成在MES系统中的一个功能模块,专门用于漆包线生产过程中的重量检…...
RabbitMQ的高级特性-事务
事务:RabbitMQ是基于AMQP协议实现的, 该协议实现了事务机制, 因此RabbitMQ也⽀持事务机制. SpringAMQP也提供了对事务相关的操作. RabbitMQ事务允许开发者确保消息的发送和接收是原⼦性的, 要么全部成功, 要么全部失败 配置事务管理器: Bean public Ra…...
Qt Linguist手册
概述 Qt 为将 Qt C 和 Qt Quick 应用程序翻译成当地语言提供了出色的支持。发布经理、翻译和开发人员可以使用 Qt 工具来完成他们的任务。 发布经理对应用程序的发布负总责。通常,他们负责协调开发人员和翻译人员的工作。他们可以使用 lupdate 工具同步源代码和翻…...
【简介Sentinel-1】
Sentinel-1是欧洲航天局哥白尼计划(GMES)中的地球观测卫星,由Sentinel-1A和Sentinel-1B两颗卫星组成。以下是对Sentinel-1的详细介绍: 一、基本信息 卫星名称:Sentinel-1 所属计划:欧洲航天局哥白尼计划…...
第 17 场小白入门赛蓝桥杯
第 17 场小白入门赛 2 北伐军费 发现每次选大的更优,所以可以排序之后,先手取右边,后手取左边。 实际发现,对于 A − B A-B A−B 的结果来说,后手对于这个式子的贡献是 − − a i --a_i −−ai ,也就…...
@antv/x6 导出图片下载,或者导出图片为base64由后端去处理。
1、导出为文件的格式,比如 PNG graph.exportPNG(function (dataURL) {console.log(dataURL);let img document.getElementById(img) as HTMLImageElement;img.src dataURL;},{backgroundColor: #fff,padding: [20, 20, 20, 20],quality: 1,width: graph.options.w…...
从零到精通:AI大模型的全方位学习路径解析,非常详细收藏我这一篇就够了
一、初聊大模型 1、什么是大模型? 大模型,通常指的是在人工智能领域中的大型预训练模型。你可以把它们想象成非常聪明的大脑,这些大脑通过阅读大量的文本、图片、声音等信息,学习到了世界的知识。这些大脑(模型&…...
PowerShell脚本在自动化Windows开发工作流程中的应用
PowerShell脚本在自动化Windows开发工作流程中的应用 在当今快速迭代的软件开发环境中,自动化已成为提高开发效率、减少人为错误、保障项目稳定性的重要手段。特别是在Windows平台上,PowerShell以其强大的脚本编写能力和对系统管理的深度集成࿰…...
【力扣 | SQL题 | 每日四题】力扣1783,1757,1747,1623,1468,1661
昨天晚上睡着了,今天把昨天的每日一题给补上。 1. 力扣1783:大满贯数量 1.1 题目: 表:Players ------------------------- | Column Name | Type | ------------------------- | player_id | int | | player_na…...
《深入探究 C++中的函数模板特化:开启编程新境界》
在 C的广袤世界中,函数模板特化是一项强大而富有魅力的技术,它为程序员提供了更高的灵活性和效率。本文将带你深入了解 C中函数模板特化是如何实现的,揭开这一神秘面纱,让你在编程之路上更上一层楼。 一、函数模板的基础概念 在…...
RTEMS面试题汇总及参考答案
目录 RTEMS是什么?它在嵌入式系统中扮演什么角色? RTEMS的全称是什么? RTEMS的主要特点有哪些? RTEMS支持哪些处理器架构? RTEMS的可剥夺型内核和不可剥夺型内核有何不同? RTEMS 的微内核设计及其优势 RTEMS 如何实现多任务处理和调度 RTEMS 的任务调度策略有哪…...
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习03(网络及IP规划)
3 网络及IP规划 3.1 容器连接网络初步规划 规划所有容器与虚拟机的三张网卡以macvlan的方式进行连接(以后根据应用可以更改),在docker下创建nat、wifi、nei、wai四张网卡,他们和虚拟机及宿主机上NIC的相关连接参数如下表所示&am…...
BLOOM 模型的核心原理、局限与未来发展方向解析
1. 引言 1.1 BLOOM 模型概述 BLOOM(BigScience Large Open-science Open-access Multilingual Language Model)是一款由多个国际研究团队联合开发的大型语言模型。BLOOM 模型旨在通过先进的 Transformer 架构处理复杂的自然语言生成与理解任务。它支持…...
Kubernetes 深度洞察:重新认识 Docker 容器的奇妙世界
《Kubernetes 深度洞察:重新认识 Docker 容器的奇妙世界》 在 Kubernetes 的学习进程中,对 Docker 容器的深入理解至关重要。这一节,我们将重新认识 Docker 容器,探索其在 Kubernetes 生态系统中的关键作用。 一、Docker 容器的基本概念 Docker 容器是一种轻量级的虚拟化…...
柔性作业车间调度(FJSP)
1.1 调度问题的研究背景 生产调度是指针对一项可分解的工作(如产品制造),在尽可能满足工艺路线、资源情况、交货期等约束条件的前提下,通过下达生产指令,安排其组成部分(操作)所使用的资源、加工时间及加工的先后顺序,以获得产品制造时间或成本最优化的一项工作。 一般研究车间…...
速盾:游戏用CDN可以吗?
游戏用CDN是一种常见的解决方案,可以提高游戏的网络性能和加载速度。CDN(Content Delivery Network,内容分发网络)能够将游戏的静态资源分布到全球各地的边缘节点上,使用户可以从离他们最近的节点获取游戏资源…...
《重生到现代之从零开始的C语言生活》—— 字符函数和字符串函数
字符函数和字符串函数 字符分类函数 大家知道字符是分为很多种类型的 就比如说’a’ ‘1’ A’等等,所以我们需要一种函数来完成字符函数的分类 这就是字符分类函数 函数需要包含头文件<ctype.h> 函数的运行规则是:如果符合下列参数就返回真 …...
双指针:滑动窗口
题目描述 给定两个字符串 S 和 T,求 S 中包含 T 所有字符的最短连续子字符串的长度,同时要求时间复杂度不得超过 O(n)。 输入输出样例 输入是两个字符串 S 和 T,输出是一个 S 字符串的子串。样例如下: 在这个样例中,…...
剑指offer20_链表中环的入口节点
链表中环的入口节点 给定一个链表,若其中包含环,则输出环的入口节点。 若其中不包含环,则输出null。 数据范围 节点 val 值取值范围 [ 1 , 1000 ] [1,1000] [1,1000]。 节点 val 值各不相同。 链表长度 [ 0 , 500 ] [0,500] [0,500]。 …...
Java多线程实现之Callable接口深度解析
Java多线程实现之Callable接口深度解析 一、Callable接口概述1.1 接口定义1.2 与Runnable接口的对比1.3 Future接口与FutureTask类 二、Callable接口的基本使用方法2.1 传统方式实现Callable接口2.2 使用Lambda表达式简化Callable实现2.3 使用FutureTask类执行Callable任务 三、…...
如何将联系人从 iPhone 转移到 Android
从 iPhone 换到 Android 手机时,你可能需要保留重要的数据,例如通讯录。好在,将通讯录从 iPhone 转移到 Android 手机非常简单,你可以从本文中学习 6 种可靠的方法,确保随时保持连接,不错过任何信息。 第 1…...
SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现
摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序,以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务,提供稳定高效的数据处理与业务逻辑支持;利用 uniapp 实现跨平台前…...
有限自动机到正规文法转换器v1.0
1 项目简介 这是一个功能强大的有限自动机(Finite Automaton, FA)到正规文法(Regular Grammar)转换器,它配备了一个直观且完整的图形用户界面,使用户能够轻松地进行操作和观察。该程序基于编译原理中的经典…...
Unsafe Fileupload篇补充-木马的详细教程与木马分享(中国蚁剑方式)
在之前的皮卡丘靶场第九期Unsafe Fileupload篇中我们学习了木马的原理并且学了一个简单的木马文件 本期内容是为了更好的为大家解释木马(服务器方面的)的原理,连接,以及各种木马及连接工具的分享 文件木马:https://w…...
Pinocchio 库详解及其在足式机器人上的应用
Pinocchio 库详解及其在足式机器人上的应用 Pinocchio (Pinocchio is not only a nose) 是一个开源的 C 库,专门用于快速计算机器人模型的正向运动学、逆向运动学、雅可比矩阵、动力学和动力学导数。它主要关注效率和准确性,并提供了一个通用的框架&…...
Aspose.PDF 限制绕过方案:Java 字节码技术实战分享(仅供学习)
Aspose.PDF 限制绕过方案:Java 字节码技术实战分享(仅供学习) 一、Aspose.PDF 简介二、说明(⚠️仅供学习与研究使用)三、技术流程总览四、准备工作1. 下载 Jar 包2. Maven 项目依赖配置 五、字节码修改实现代码&#…...
Mysql中select查询语句的执行过程
目录 1、介绍 1.1、组件介绍 1.2、Sql执行顺序 2、执行流程 2.1. 连接与认证 2.2. 查询缓存 2.3. 语法解析(Parser) 2.4、执行sql 1. 预处理(Preprocessor) 2. 查询优化器(Optimizer) 3. 执行器…...
R语言速释制剂QBD解决方案之三
本文是《Quality by Design for ANDAs: An Example for Immediate-Release Dosage Forms》第一个处方的R语言解决方案。 第一个处方研究评估原料药粒径分布、MCC/Lactose比例、崩解剂用量对制剂CQAs的影响。 第二处方研究用于理解颗粒外加硬脂酸镁和滑石粉对片剂质量和可生产…...
