目录

知识点一:启动一个pod

 1、使用命令启动一个nginx pod

1.1、访问刚才创建的pod的nginx服务

 1.2、删除deployment

2、将pod里的服务发布出去

 首先创建根据yaml文件创建pod

 2.1、创建Service

2.2、访问发布的pod

 3、利用yaml文件创建pod

3.1、根据yaml文件启动pod

3.2、删除pod

4、pod的几种状态 

知识点二:启动pod的流程

 知识点三:pod有哪些调度算法

1、 kubectl describe node k8s-master  输出一个node的详细信息

 2、pod的重启策略

 知识点四:pod的通信方式

知识点五:k8s的各种控制器

1、k8s里面有哪些控制器?

1.1、ReplicaSET 副本控制器 

1.2、DaemonSet 

 1.3、Job

2、deployment,replicaSET,pod的关系

2.1、既然pod是replicaSET启动的,那么删除replicaSET会发生什么?

知识点一:启动一个pod

 1、使用命令启动一个nginx pod

[root@k8s-master ~]# kubectl create deployment k8s-nginx --image=nginx -r 3
deployment.apps/k8s-nginx created
[root@k8s-master ~]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
k8s-nginx-6d779d947c-58j42   1/1     Running   0          114s
k8s-nginx-6d779d947c-mphkp   1/1     Running   0          114s
k8s-nginx-6d779d947c-zwplb   1/1     Running   0          114s
[root@k8s-master ~]# kubectl get deploy
NAME        READY   UP-TO-DATE   AVAILABLE   AGE
k8s-nginx   3/3     3            3           3m10s
[root@k8s-master ~]# kubectl get pod -o wide
NAME                         READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
k8s-nginx-6d779d947c-58j42   1/1     Running   0          13m   10.244.1.2   k8s-node1   <none>           <none>
k8s-nginx-6d779d947c-mphkp   1/1     Running   0          13m   10.244.2.2   k8s-node2   <none>           <none>
k8s-nginx-6d779d947c-zwplb   1/1     Running   0          13m   10.244.3.4   k8s-node3   <none>           <none>

 ########################################################################################## 

1.1、访问刚才创建的pod的nginx服务

目前只能在内部访问pod的nginx服务,因为还没有将它发布出去,10.244网段是k8s内部的网段

[root@k8s-master ~]# curl 10.244.1.2
<!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>

 ########################################################################################## 

 1.2、删除deployment

[root@k8s-master ~]# kubectl get deploy
NAME        READY   UP-TO-DATE   AVAILABLE   AGE
k8s-nginx   3/3     3            3           18h
[root@k8s-master ~]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
k8s-nginx-6d779d947c-58j42   1/1     Running   0          18h
k8s-nginx-6d779d947c-mphkp   1/1     Running   0          18h
k8s-nginx-6d779d947c-zwplb   1/1     Running   0          18h
[root@k8s-master ~]# kubectl delete deployment  k8s-nginx
deployment.apps "k8s-nginx" deleted
[root@k8s-master ~]# kubectl get deploy
No resources found in default namespace.
[root@k8s-master ~]# kubectl get pod
No resources found in default namespace.

 ########################################################################################## 

2、将pod里的服务发布出去

yaml文件:

[root@k8s-master pod]# cat my_nginx.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 3
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80
[root@k8s-master pod]# kubectl apply -f my_nginx.yaml 
deployment.apps/my-nginx created
[root@k8s-master pod]# kubectl get deploy
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
my-nginx   3/3     3            3           12s
[root@k8s-master pod]# kubectl get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
my-nginx-cf54cdbf7-5tnfx   1/1     Running   0          24s   10.244.1.5   k8s-node1   <none>           <none>
my-nginx-cf54cdbf7-c8wbq   1/1     Running   0          24s   10.244.2.6   k8s-node2   <none>           <none>
my-nginx-cf54cdbf7-rhqcv   1/1     Running   0          24s   10.244.3.7   k8s-node3   <none>           <none>

 ########################################################################################## 

 2.1、创建Service

my_service.yaml内容:

apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 80
    protocol: TCP
    name: http
  selector:
    run: my-nginx

 创建service

[root@k8s-master pod]# kubectl apply -f my_service.yaml 
service/my-nginx created
[root@k8s-master pod]# kubectl get service
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.1.0.1      <none>        443/TCP          24h
my-nginx     NodePort    10.1.20.144   <none>        8080:32697/TCP   5s

 ########################################################################################## 

2.2、访问发布的pod

我们只要随便访问k8s几区任何一台node节点服务器,包括master

k8s创建pod - 启动pod的流程-LMLPHP

k8s创建pod - 启动pod的流程-LMLPHP

########################################################################################## 

 3、利用yaml文件创建pod

以下是nginx-pod.yaml文件内容

apiVersion: v1   # k8s的api版本 --》用来给k8s传递参数
kind: Pod        # k8s的资源对象类型:pod,deployment,replicaSET,daemonSET
metadata:        # 定义的元数据,描述数据
  name: sc-nginx    # pod的名字
spec:            # 详细信息,指定的信息
  containers:    # 容器
  - name: nginx  # 容器名字
    image: nginx:1.14.2     #容器镜像版本
    ports:       # 端口
    - containerPort: 80

 ########################################################################################## 

3.1、根据yaml文件启动pod

[root@k8s-master ~]# vim nginx-pod.yaml 
[root@k8s-master ~]# kubectl apply -f nginx-pod.yaml 
pod/sc-nginx created
[root@k8s-master ~]# kubectl get pod -o wide
NAME       READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
sc-nginx   1/1     Running   0          80s   10.244.2.3   k8s-node2   <none>           <none>

3.2、删除pod

[root@k8s-master ~]# kubectl delete pod sc-nginx
pod "sc-nginx" deleted
[root@k8s-master ~]# kubectl get pod
No resources found in default namespace.

########################################################################################## 

4、pod的几种状态 

[root@k8s-master ~]# kubectl get  pod -n kube-system
NAME                                 READY   STATUS             RESTARTS         AGE
coredns-6d8c4cb4d-92g7b              0/1     CrashLoopBackOff   32 (3m44s ago)   2d23h
coredns-6d8c4cb4d-kl4q5              0/1     CrashLoopBackOff   32 (3m44s ago)   2d23h
etcd-k8s-master                      1/1     Running            0                2d23h
kube-apiserver-k8s-master            1/1     Running            0                2d23h
kube-controller-manager-k8s-master   1/1     Running            0                2d23h
kube-proxy-422b5                     1/1     Running            0                2d23h
kube-proxy-6qpcz                     1/1     Running            0                2d23h
kube-proxy-ggnnt                     1/1     Running            0                2d23h
kube-proxy-vjcnc                     1/1     Running            0                2d23h
kube-scheduler-k8s-master            1/1     Running            0                2d23h

##########################################################################################

知识点二:启动pod的流程

 k8s创建pod - 启动pod的流程-LMLPHP

 ##########################################################################################

 知识点三:pod有哪些调度算法

1、 kubectl describe node k8s-master  输出一个node的详细信息

[root@k8s-master ~]# kubectl describe node k8s-master
Name:               k8s-master
Roles:              control-plane,master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=k8s-master
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/control-plane=
                    node-role.kubernetes.io/master=
                    node.kubernetes.io/exclude-from-external-load-balancers=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"fe:ca:d8:cc:01:2e"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.44.210
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Sun, 25 Sep 2022 18:20:27 +0800
Taints:             node-role.kubernetes.io/master:NoSchedule
Unschedulable:      false
Lease:
  HolderIdentity:  k8s-master
  AcquireTime:     <unset>
  RenewTime:       Wed, 28 Sep 2022 17:36:36 +0800
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Sun, 25 Sep 2022 18:33:20 +0800   Sun, 25 Sep 2022 18:33:20 +0800   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Wed, 28 Sep 2022 17:33:08 +0800   Sun, 25 Sep 2022 18:20:26 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Wed, 28 Sep 2022 17:33:08 +0800   Sun, 25 Sep 2022 18:20:26 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Wed, 28 Sep 2022 17:33:08 +0800   Sun, 25 Sep 2022 18:20:26 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Wed, 28 Sep 2022 17:33:08 +0800   Sun, 25 Sep 2022 18:33:28 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.44.210
  Hostname:    k8s-master
Capacity:
  cpu:                4
  ephemeral-storage:  17394Mi
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             1863028Ki
  pods:               110
Allocatable:
  cpu:                4
  ephemeral-storage:  16415037823
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             1760628Ki
  pods:               110
System Info:
  Machine ID:                 6d6ca2c7ec0f478097733b00d2892ca0
  System UUID:                0A004D56-3924-4215-F717-9E4DAD9C840B
  Boot ID:                    dd78d95d-a6e7-460e-892b-8d4cf8191823
  Kernel Version:             3.10.0-1160.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://20.10.18
  Kubelet Version:            v1.23.6
  Kube-Proxy Version:         v1.23.6
PodCIDR:                      10.244.0.0/24
PodCIDRs:                     10.244.0.0/24
Non-terminated Pods:          (6 in total)
  Namespace                   Name                                  CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                                  ------------  ----------  ---------------  -------------  ---
  kube-flannel                kube-flannel-ds-rphnc                 100m (2%)     100m (2%)   50Mi (2%)        50Mi (2%)      2d23h
  kube-system                 etcd-k8s-master                       100m (2%)     0 (0%)      100Mi (5%)       0 (0%)         2d23h
  kube-system                 kube-apiserver-k8s-master             250m (6%)     0 (0%)      0 (0%)           0 (0%)         2d23h
  kube-system                 kube-controller-manager-k8s-master    200m (5%)     0 (0%)      0 (0%)           0 (0%)         2d23h
  kube-system                 kube-proxy-ggnnt                      0 (0%)        0 (0%)      0 (0%)           0 (0%)         2d23h
  kube-system                 kube-scheduler-k8s-master             100m (2%)     0 (0%)      0 (0%)           0 (0%)         2d23h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                750m (18%)  100m (2%)
  memory             150Mi (8%)  50Mi (2%)
  ephemeral-storage  0 (0%)      0 (0%)
  hugepages-1Gi      0 (0%)      0 (0%)
  hugepages-2Mi      0 (0%)      0 (0%)
Events:              <none>

 ########################################################################################## 

 2、pod的重启策略

 ##########################################################################################

 知识点四:pod的通信方式

kubernetes 的网络模型假定了所有Pod都在一个可以直接连通的扁平的网络空间中,kubernetes假定这个网络已经存在,

 ##########################################################################################

知识点五:k8s的各种控制器

1、k8s里面有哪些控制器?

1.1、ReplicaSET 副本控制器 

1.2、DaemonSet 

 1.3、Job

 ##########################################################################################

2、deployment,replicaSET,pod的关系

k8s创建pod - 启动pod的流程-LMLPHP

[root@k8s-master ~]# kubectl create deployment k8s-nginx --image=nginx -r 3
deployment.apps/k8s-nginx created
[root@k8s-master ~]# kubectl get pod -o wide
NAME                         READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
k8s-nginx-6d779d947c-hd64b   1/1     Running   0          21s   10.244.1.3   k8s-node1   <none>           <none>
k8s-nginx-6d779d947c-j9pkd   1/1     Running   0          21s   10.244.3.5   k8s-node3   <none>           <none>
k8s-nginx-6d779d947c-rf7tm   1/1     Running   0          21s   10.244.2.4   k8s-node2   <none>           <none>
[root@k8s-master ~]# kubectl get deploy
NAME        READY   UP-TO-DATE   AVAILABLE   AGE
k8s-nginx   3/3     3            3           27s
[root@k8s-master ~]# kubectl get replicaset
NAME                   DESIRED   CURRENT   READY   AGE
k8s-nginx-6d779d947c   3         3         3       41s

2.1、既然pod是replicaSET启动的,那么删除replicaSET会发生什么?

[root@k8s-master ~]# kubectl delete replicaset k8s-nginx-6d779d947c
replicaset.apps "k8s-nginx-6d779d947c" deleted
[root@k8s-master ~]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
k8s-nginx-6d779d947c-2xp8r   1/1     Running   0          7s
k8s-nginx-6d779d947c-gw5x8   1/1     Running   0          7s
k8s-nginx-6d779d947c-rmx9x   1/1     Running   0          7s
[root@k8s-master ~]# kubectl get rs
NAME                   DESIRED   CURRENT   READY   AGE
k8s-nginx-6d779d947c   3         3         3       12s

 ##########################################################################################

09-29 03:53