文章目录

  • 1.什么是pod
    • 1.2 pod控制器种类
  • 2. kubernetes网络模型
    • 2.2 同节点Pod之间的通信
    • 2.3 不同节点上的Pod通信
    • 2.4 Pod与Service
  • 3. kubectl命令的使用
  • 4. 小结

1.什么是pod

在kubernetes集群中,pod的创建方式可以分为两类

  • 自主式pod:kubernetes直接创建出来的pod,这种pod删除后就没有了,也不会重建
  • 控制器创建的pod,通过控制器创建的pod,这种pod删除之后还会自动创建,相当于自我恢复

pod控制器是管理pod的中间层,使用了pod控制器之后,我们只需要告诉pod控制器想要运行多少个什么样的pod就可以了,它会创建出满足条件的pod,并确保每个pod处于用户期望的状态,如果pod运行过程中出现了故障,控制器也会基于指定策略重启或者重建pod

1.2 pod控制器种类

  • ReplicationController

    比较原始的pod控制器,已经启用,由ReplicaSet替代

  • ReplicaSet

    保证指定数量pod运行,并支持对pod数量进行变更、镜像版本变更

  • Deployment

    通过控制ReplicaSet资源来控制pod,并支持滚动升级、版本回退,企业中最常用的资源类型

  • Horizontal Pod Autoscaler

    可以根据集群负载自动调整pod的数量,实现削峰填谷,当pod处于高峰的时候自动增加pod的副本数,当pod处于低峰时自动减少pod的副本数,hpa不会将pod的副本数减少的比期望的副本数还要低

  • StateFulSet:有状态副本集,可以管理有状态的应用

  • DaemonSet:如果需要在每个node上运行一个副本的时候可以用DaemonSet

  • Job:它创建出来的pod只要完成任务就立即退出,不需要重启或重建,用于执行一次性任务

  • Cronjob:它创建的Pod负责周期性任务控制,不需要持续后台运行
    以上所有控制器都是用来实现一种特定的应用管理的。

2. kubernetes网络模型

Kubernetes 采用的是基于扁平地址空间的、非NAT的网络模型,每个Pod有自己唯一的IP地址。

网络是由系统管理员或CNI(container network interface)插件建立的,而非K8S本身。

K8S并不会要求用户使用指定的网络技术,但是会授权Pod(容器)在不同节点上的相互通信。

2.2 同节点Pod之间的通信

在容器启动前,会为容器创建一个虚拟Ethernet接口对,这个接口对类似于管道的两端,其中一端在主机命名空间中,另外一端在容器命名空间中,并命名为eth0。在主机命名空间的接口会绑定到网桥。网桥的地址段会取IP赋值给容器的eth0接口。

2.3 不同节点上的Pod通信

  • 物理桥接,但是在一定规模下容易产生网络风暴,不建议使用
  • Overlay Network 通过隧道的方式转发报文

当报文从A节点上的容器发送到B节点上的容器时,报文会先通过veth接口对到网桥,再由网桥到A节点的物理适配器,再通过网线传输到B节点的物理适配器,再通过B的网桥,经过接口对到达目标容器。

2.4 Pod与Service

各节点之间是相互通信的,节点也就是真机之间的通信,因为service网络是一个iptables规则,且与真机是相连的,而pod和service是我们初始化的时候通过flannel网络进行互联,且属于同一网段。

3. kubectl命令的使用

[root@master ~]# kubectl create deployment --help
Create a deployment with the specified name.Aliases:
deployment, deployExamples:# Create a deployment named my-dep that runs the busybox image.kubectl create deployment my-dep --image=busybox# Create a deployment with commandkubectl create deployment my-dep --image=busybox -- date# Create a deployment named my-dep that runs the nginx image with 3 replicas.kubectl create deployment my-dep --image=nginx --replicas=3# Create a deployment named my-dep that runs the busybox image and expose port 5701.kubectl create deployment my-dep --image=busybox --port=5701Options:--allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.--dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.--field-manager='kubectl-create': Name of the manager used to track field ownership.--image=[]: Image names to run.-o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.--port=-1: The port that this container exposes.-r, --replicas=1: Number of replicas to create. Default is 1.--save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.--template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].--validate=true: If true, use a schema to validate the input before sending itUsage:kubectl create deployment NAME --image=image -- [COMMAND] [args...] [options]创建一个busybox镜像名为my-dep的容器
[root@master ~]# kubectl create deployment my-dep --image=busybox
deployment.apps/my-dep created
[root@master ~]#
[root@master ~]# kubectl get pods -o wide
NAME                      READY   STATUS      RESTARTS   AGE    IP           NODE    NOMINATED NODE   READINESS GATES
my-dep-68d7dcffc4-drt92   0/1     Completed   0          9s     10.244.3.2   node1   <none>           <none>
nginx-6799fc88d8-qqf8d    1/1     Running     1          2d7h   10.244.2.3   node2   <none>           <none>//创建3个nginx镜像容器
[root@master ~]# kubectl create deployment my-dep2 --image=nginx --replicas=3
deployment.apps/my-dep2 created
[root@master ~]# kubectl get pods -o wide
NAME                       READY   STATUS              RESTARTS   AGE     IP           NODE    NOMINATED NODE   READINESS GATES
my-dep-68d7dcffc4-drt92    0/1     CrashLoopBackOff    6          9m50s   10.244.3.2   node1   <none>           <none>
my-dep2-64d5dff8d8-6z4pl   0/1     ContainerCreating   0          3s      <none>       node1   <none>           <none>
my-dep2-64d5dff8d8-f7v9z   0/1     ContainerCreating   0          3s      <none>       node2   <none>           <none>
my-dep2-64d5dff8d8-kqs55   0/1     ContainerCreating   0          3s      <none>       node2   <none>           <none>
nginx-6799fc88d8-qqf8d     1/1     Running             1          2d7h    10.244.2.3   node2   <none>           <none>//暴露80端口号
[root@master ~]# kubectl create deployment web01 --image nginx --port=80
deployment.apps/web01 created
[root@master ~]# kubectl get pods -o wide
NAME                       READY   STATUS              RESTARTS   AGE     IP           NODE    NOMINATED NODE   READINESS GATES
my-dep-68d7dcffc4-drt92    0/1     CrashLoopBackOff    7          12m     10.244.3.2   node1   <none>           <none>
my-dep2-64d5dff8d8-6z4pl   1/1     Running             0          2m57s   10.244.3.3   node1   <none>           <none>
my-dep2-64d5dff8d8-f7v9z   1/1     Running             0          2m57s   10.244.2.4   node2   <none>           <none>
my-dep2-64d5dff8d8-kqs55   1/1     Running             0          2m57s   10.244.2.5   node2   <none>           <none>
my-dep3-596db44fdd-44c7b   0/1     CrashLoopBackOff    1          60s     10.244.3.4   node1   <none>           <none>
nginx-6799fc88d8-qqf8d     1/1     Running             1          2d7h    10.244.2.3   node2   <none>           <none>
web01-59859fb9db-qz6vr     0/1     ContainerCreating   0          2s      <none>       node1   <none>           <none>[root@master ~]# curl 10.244.3.5: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>
// 启动一个 nginx pod
[root@master ~]# kubectl run nginx --image nginx
[root@master ~]# kubectl get pods -o wide
NAME                       READY   STATUS             RESTARTS   AGE     IP           NODE    NOMINATED NODE   READINESS GATES
nginx                      1/1     Running            0          4m38s   10.244.2.6   node2   <none>           <none>[root@master ~]# kubectl delete pods nginx  //删除nginx的pod
pod "nginx" deleted[root@master ~]# kubectl run nginx --images nginx --port 80  // 暴露容器的80端口号// 在容器中设置标签“app=nginx”和“env=prod”
[root@master ~]# kubectl run nginx --image nginx --labels "aap=nginx,env=prod"
pod/nginx created//查看nginx信息
[root@master ~]# kubectl describe pod nginx
Name:         nginx
Namespace:    default
Priority:     0
Node:         node2/192.168.216.215
Start Time:   Mon, 20 Dec 2021 00:21:47 +0800
Labels:       run=nginx
Annotations:  <none>
Status:       Running
IP:           10.244.2.6
IPs:IP:  10.244.2.6
Containers:nginx:Container ID:   docker://2fdf571cd384581813f5fef184d148f87121e5a4f6855ef1ca28b762fb9ab20aImage:          nginx
。。。略//测试运行并不会真的运行
[root@master ~]# kubectl run nginx --image nginx --dry-run server
W1220 00:31:43.989318  130193 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
pod/nginx created (dry run)
[root@master ~]# kubectl delete  my-dep2-64d5dff8d8-f7v9z
error: the server doesn't have a resource type "my-dep2-64d5dff8d8-f7v9z"
[root@master ~]# kubectl delete  my-dep2
error: the server doesn't have a resource type "my-dep2"
[root@master ~]# kubectl delete deployment my-dep2
deployment.apps "my-dep2" deleted
使用deployment类型,因为我们当时创建的时候使用的是deployment类型[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        2d8h
nginx        NodePort    10.101.87.17   <none>        80:30337/TCP   2d7h
[root@master ~]# kubectl get pod
NAME                       READY   STATUS             RESTARTS   AGE
my-dep-68d7dcffc4-pnfl5    0/1     CrashLoopBackOff   7          14m
my-dep3-596db44fdd-44c7b   0/1     CrashLoopBackOff   8          21m
nginx                      1/1     Running            0          15m
nginx-6799fc88d8-qqf8d     1/1     Running            1          2d7h
web01-59859fb9db-qz6vr     1/1     Running            0          20m
[root@master ~]#  kubectl delete svc nginx
service "nginx" deleted
[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   2d8h
[root@master ~]# kubectl get pod
NAME                       READY   STATUS             RESTARTS   AGE
my-dep-68d7dcffc4-pnfl5    0/1     CrashLoopBackOff   7          15m
my-dep3-596db44fdd-44c7b   0/1     CrashLoopBackOff   8          22m
nginx                      1/1     Running            0          16m
nginx-6799fc88d8-qqf8d     1/1     Running            1          2d7h
web01-59859fb9db-qz6vr     1/1     Running            0          21m
// 删除service类型的pod//删除所有pod
[root@master ~]# kubectl delete pods --all
pod "my-dep-68d7dcffc4-pnfl5" deleted
pod "my-dep3-596db44fdd-44c7b" deleted
pod "nginx" deleted
pod "nginx-6799fc88d8-qqf8d" deleted
pod "web01-59859fb9db-qz6vr" deleted
[root@master ~]# kubectl get pod
NAME                       READY   STATUS             RESTARTS   AGE
my-dep-68d7dcffc4-85trf    0/1     CrashLoopBackOff   4          3m33s
my-dep3-596db44fdd-jx9sb   0/1     CrashLoopBackOff   4          3m33s
nginx-6799fc88d8-mqrz5     1/1     Running            0          3m33s
web01-59859fb9db-r9d52     1/1     Running            0          3m33s
//将pod中的80暴露到宿主机上的8080
[root@master ~]# kubectl expose deployment web01 --port 8080 --target-port 80
service/web01 exposed
[root@master ~]# curl 10.244.3.9: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>
[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP    2d8h
web01        ClusterIP   10.105.213.189   <none>        8080/TCP   119s
[root@master ~]# curl 10.105.213.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>
<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
[root@master ~]# kubectl get pods
NAME                       READY   STATUS             RESTARTS   AGE
my-dep-68d7dcffc4-85trf    0/1     CrashLoopBackOff   6          8m
my-dep3-596db44fdd-jx9sb   0/1     CrashLoopBackOff   6          8m
nginx-6799fc88d8-mqrz5     1/1     Running            0          8m
web01-59859fb9db-r9d52     1/1     Running            0          8m//详细信息
[root@master ~]# kubectl get pods -o wide
NAME                       READY   STATUS             RESTARTS   AGE     IP           NODE    NOMINATED NODE   READINESS GATES
my-dep-68d7dcffc4-85trf    0/1     CrashLoopBackOff   6          8m34s   10.244.2.8   node2   <none>           <none>
my-dep3-596db44fdd-jx9sb   0/1     CrashLoopBackOff   6          8m34s   10.244.2.9   node2   <none>           <none>
nginx-6799fc88d8-mqrz5     1/1     Running            0          8m34s   10.244.3.8   node1   <none>           <none>
web01-59859fb9db-r9d52     1/1     Running            0          8m34s   10.244.3.9   node1   <none>           <none>//查看你指定类型的pod,类型加pod名
[root@master ~]# kubectl get deployment web01
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
web01   1/1     1            1           31m//列出所有服务
[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP    2d8h
web01        ClusterIP   10.105.213.189   <none>        8080/TCP   6m2s//查看某个参数如何定义
[root@master ~]# kubectl explain pod
KIND:     Pod
VERSION:  v1DESCRIPTION:Pod is a collection of containers that can run on a host. This resource iscreated by clients and scheduled onto hosts.FIELDS:apiVersion   <string>APIVersion defines the versioned schema of this representation of anobject. Servers should convert recognized schemas to the latest internalvalue, and may 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     <Object>Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadataspec <Object>Specification of the desired behavior of the pod. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-statusstatus       <Object>Most recently observed status of the pod. This data may not be up to date.Populated by the system. Read-only. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status//查看更多
[root@master ~]# kubectl explain pod.spec
KIND:     Pod
VERSION:  v1RESOURCE: spec <Object>DESCRIPTION:Specification of the desired behavior of the pod. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-statusPodSpec is a description of a pod.FIELDS:activeDeadlineSeconds        <integer>Optional duration in seconds the pod may be active on the node relative toStartTime before the system will actively try to mark it failed and kill//查看资源信息
[root@master ~]# kubectl describe pod nginx
Name:         nginx-6799fc88d8-qqf8d
Namespace:    default
Priority:     0
Node:         node2/192.168.216.215
Start Time:   Fri, 17 Dec 2021 17:03:35 +0800
Labels:       app=nginxpod-template-hash=6799fc88d8
Annotations:  <none>
Status:       Running
IP:           10.244.2.3
IPs:IP:           10.244.2.3
Controlled By:  ReplicaSet/nginx-6799fc88d8
Containers:nginx:Container ID:   docker://58a1f79fc45b533650696800c4bbab91634dd58adf2782fdee94987c3ed53690Image:          nginxImage ID:       docker-pullable://nginx@sha256:d13dca1855de09e2fe392c58a66dd73d4ff4b71da4d1720bcf3f47b48c53ca1dPort:           <none>Host Port:      <none>State:          RunningStarted:      Tue, 21 Dec 2021 12:00:42 +0800Last State:     TerminatedReason:       ErrorExit Code:    255Started:      Fri, 17 Dec 2021 17:04:16 +0800Finished:     Tue, 21 Dec 2021 11:59:52 +0800Ready:          TrueRestart Count:  1Environment:    <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from default-token-2xdt8 (ro)
Conditions:Type              StatusInitialized       True Ready             True ContainersReady   True PodScheduled      True
Volumes:default-token-2xdt8:Type:        Secret (a volume populated by a Secret)SecretName:  default-token-2xdt8Optional:    false
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//可编辑资源信息
[root@master ~]# kubectl edit deployment nginx
Edit cancelled, no changes made.//动态扩展。扩容或缩容 Deployment、ReplicaSet、Replication Controller或 Job 中Pod数量
[root@master ~]# kubectl get deployment
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           3d19h
[root@master ~]# kubectl scale --replicas 3 deployment/nginx
deployment.apps/nginx scaled
[root@master ~]#  kubectl get deployment
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   2/3     3            2           3d19h
[root@master ~]# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-6799fc88d8-658ql   1/1     Running   0          20s
nginx-6799fc88d8-qqf8d   1/1     Running   1          3d19h
nginx-6799fc88d8-tp2ts   1/1     Running   0          20s//自动扩展,给定一个范围,自动根据业务的访问量增加或减少
//最少为1,最多为5
[root@master ~]# kubectl autoscale --min 1 --max 5 deployment/nginx
horizontalpodautoscaler.autoscaling/nginx autoscaled
[root@master ~]# kubectl get hpa
NAME    REFERENCE          TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
nginx   Deployment/nginx   <unknown>/80%   1         5         0          8s//显示集群信息
[root@master ~]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.216.200:6443
KubeDNS is running at https://192.168.216.200:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.//设置标签
[root@master ~]# kubectl label deployment/nginx user=xxx
deployment.apps/nginx labeled//列出支持的资源类型
[root@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
。。。略//以组的形式列出api版本
[root@master ~]# kubectl api-versions
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
。。。略//输出pod或指定资源中容器的日志。如果pod中只有一个容器,则容器名是可选的
[root@master ~]# kubectl logs deployment/nginx
Found 3 pods, using pod/nginx-6799fc88d8-qqf8d
/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/21 04:00:42 [notice] 1#1: using the "epoll" event method
2021/12/21 04:00:42 [notice] 1#1: nginx/1.21.4
2021/12/21 04:00:42 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2021/12/21 04:00:42 [notice] 1#1: OS: Linux 4.18.0-305.3.1.el8.x86_64
2021/12/21 04:00:42 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/12/21 04:00:42 [notice] 1#1: start worker processes
2021/12/21 04:00:42 [notice] 1#1: start worker process 31
2021/12/21 04:00:42 [notice] 1#1: start worker process 32
2021/12/21 04:00:42 [notice] 1#1: start worker process 33
2021/12/21 04:00:42 [notice] 1#1: start worker process 34//进到容器内执行一个命令 可以加-it保持会话
[root@master ~]# kubectl exec deployment/nginx date
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Tue Dec 21 04:18:49 UTC 2021//转发一个或多个端口到pod里面去,不指定就是随机
[root@master ~]# kubectl port-forward nginx-6799fc88d8-658ql :80
Forwarding from 127.0.0.1:38497 -> 80
Forwarding from [::1]:38497 -> 80//拷贝文件或目录到容器中,或者从容器内向外拷贝
[root@master ~]# kubectl cp anaconda-ks.cfg nginx-6799fc88d8-658ql:/tmp
[root@master ~]# kubectl exec nginx-6799fc88d8-658ql -- ls -l /tmp
total 4
-rw------- 1 root root 1084 Dec 21 04:21 anaconda-ks.cfg

4. 小结

在Kubernetes上部署应用流程:

  1. 制作镜像
    dockerfile
    基于容器制作
  2. 使用控制器部署镜像(下面三,任选一个)
    Delopment
    StatefulSet
    DaemonSet
  3. 对外暴露应用,创建一个service让它能够访问
  4. 日志、监控
  5. 日常运维

基本资源概念

pod:k8s最小部署单元,一组容器的集合
Deployment:最常见的控制器,用于更高级别部署和管理pod
Serivce:为一组pod提供负载均衡,对外提供统一访问入口
Label:标签,附加到某个资源上,用于关联对象、查询和筛选
Namespaces:命名空间,将对象逻辑上隔离,也利于权限控制

命名空间

命名空间(Namespace):Kubernetes将资源对象逻辑上隔离,从而形成多个虚拟集群。
应用场景:

  • 根据不同团队划分命名空间
  • 根据项目划分命名空间

4种命名空间

  • default:默认命名空间
  • kube-system: K8s系统方面的命名空间.
  • kube-public: 公开的命名空间,谁都可以访问
  • kube-node-lease: K8s内部命名空间

两种方法指定资源命名空间

  • 命令行加-n
  • yaml资源元数据里指定namespace字段

kubernetes的pod分类,网络模型以及kuberctl命令的使用相关推荐

  1. Kubernetes中pod分类、核心组件、网络模型及kubectl命令使用

    文章目录 Kubernetes中pod分类.核心组件.网络模型及kubectl命令使用 1.k8s中pod分类 2.核心组件 3.网络模型 4.kubectl常用命令使用 Kubernetes中pod ...

  2. k8s pod分类、核心组件、网络模型、kubectl常用命令

    k8s的pod分类.核心组件.网络模型.kubectl常用命令 K8s基本概念 pod分类 核心组件 K8s的三种网络模型 kubectl常用操作 kubeconfig配置文件 kubectl管理命令 ...

  3. Kubernetes容器网络及网络模型

    1.Docker 网络模型 在讨论Kubernetes网络之前,让我们先来看一下Docker网络.Docker采用插件化的网络模式,默认提供bridge.host.none.overlay.macla ...

  4. kubernetes之pod健康检查

    目录 kubernetes之pod健康检查 1.概述和分类 2.LivenessProbe探针(存活性探测) 3.ReadinessProbe探针(就绪型探测) 4.探针的实现方式 4.1.ExecA ...

  5. Kubernetes中Pod生命周期

    在 Kubernetes中Pod是容器管理的最小单位, 有着各种各样的Pod管理器. 那么一个Pod从启动到释放, 在这期间经历了哪些过程呢? Pod自开始创建, 到正常运行, 再到释放, 其时间跨度 ...

  6. 容器编排技术 -- Kubernetes DNS Pod 与 Service 介绍

    容器编排技术 -- Kubernetes DNS Pod 与 Service 介绍 1 介绍 2 怎样获取 DNS 名字? 3 支持的 DNS 模式 3.1 Service 3.1.1 A 记录 3. ...

  7. 4 Kubernetes资源-Pod控制器(2)

    4 Kubernetes资源-Pod控制器(2) 4.3 DaemonSet DaemonSet确保Pod在所有Node节点运行一个副本,当有Node节点添加时会自动在新的节点创建Pod.常用于每个N ...

  8. Kubernetes的Pod详解

    文章目录 Pod生命周期 创建和终止 初始化容器 钩子函数 容器探测 示例 重启策略 Pod调度 定向调度 亲和性调度 污点和容忍 污点(Taints) 容忍(Toleration) Pod生命周期 ...

  9. Kubernetes 固定 Pod IP 地址方法

    第七章 Kubernetes 固定 Pod IP 地址方法 文章目录 第七章 Kubernetes 固定 Pod IP 地址方法 一.自定义 IP 地址池 1.下载 calico 管理工具 calic ...

最新文章

  1. 用一条sql语句删除表中所相同记录
  2. div居中与div内容居中,不一样
  3. linux与unix时间戳互转
  4. [1204 寻找子串位置] 解题报告
  5. Duration(2020多校第二场D)
  6. 【转】DICOM:DICOM三大开源库对比分析之“数据加载”
  7. vue java图片懒加载_vue 实现图片懒加载功能
  8. Struts2 Action与Servlet API耦合
  9. drain open 线与_再转一个:push-pull and open-drain,开漏(open drain)和开集(open collector...
  10. 最大值、数据排序、九九乘法表、杨辉三角
  11. 黑马vue实战项目-(七)订单管理页面的开发
  12. 判断浏览器内核是否是IE8及其以下
  13. mac怎么无线打印机连接到服务器,Mac电脑怎么连接打印机
  14. 网卡TSO、UFO、GSO、LRO、GRO和RSS介绍
  15. UnityShader源码2017---学习笔记与自我拓展019
  16. 易捷行云新一代私有云全场景智能统一运维|轻运维之场景化运维
  17. Python简介及入门
  18. js html 图片贴纸,Sticker.js 在网页实现便签贴纸效果 - 文章教程
  19. 根据汉字,获取拼音首字母(转)
  20. 模拟机械键盘音效的软件

热门文章

  1. 通过Feign调用接口,返回数据时出现数据乱码
  2. 杜比全景声深受好莱坞青睐
  3. 家谱管理系统性能要求_华北工控 | 嵌入式计算机在智慧社区管理系统中的大范畴应用...
  4. 详解安装msdn 2015及其注意事项
  5. 【STM32移植机智云】超详细教程#2ESP8266移植机智云教程‘代码移植’
  6. 数仓数据处理与数据流向
  7. Java-循环语句 控制跳转语句及方法(函数)
  8. adt变频器故障代码ol2_众为兴 ADT-CNC040C车床控制系统
  9. slam算法_[招聘] SLAM算法工程师(实习生亦可)
  10. 应用Abaqus有限元软件动力学模块模拟岩石单轴压缩断裂过程