【Kubernetes】创建Pod并分配到指定节点Node1

一、编译yaml文件

[[email protected] Tools]# cat hello-world-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:
  nodeSelector:
    type: node1
  containers:
  - name: hello
    image: "ubuntu:14.04"
    command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]

二、创建并查看运行状态

[[email protected] Tools]# kubectl create -f hello-world-pod.yaml
pod/hello-world created
[[email protected] Tools]# kubectl get pod hello-world
NAME          READY   STATUS    RESTARTS   AGE
hello-world   1/1     Running   0          8m2s
[[email protected] Tools]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                    READY   STATUS    RESTARTS   AGE
default       hello-world                             1/1     Running   0          3s
kube-system   coredns-bccdc95cf-plst5                 1/1     Running   13         36d
kube-system   coredns-bccdc95cf-vkqzr                 1/1     Running   13         36d
kube-system   etcd-k8s-master                         1/1     Running   15         36d
kube-system   kube-apiserver-k8s-master               1/1     Running   15         36d
kube-system   kube-controller-manager-k8s-master      1/1     Running   15         36d
kube-system   kube-flannel-ds-amd64-4g6qc             1/1     Running   6          36d
kube-system   kube-flannel-ds-amd64-ccj8v             1/1     Running   14         36d
kube-system   kube-flannel-ds-amd64-fhrfj             1/1     Running   8          36d
kube-system   kube-proxy-jp6mp                        1/1     Running   13         36d
kube-system   kube-proxy-rkbcx                        1/1     Running   6          36d
kube-system   kube-proxy-rmkqm                        1/1     Running   8          36d
kube-system   kube-scheduler-k8s-master               1/1     Running   15         36d
kube-system   kubernetes-dashboard-6db4897b74-lqfl6   1/1     Running   1          24h


注意点:将pod分配到指定的节点
①为Node添加label

kubectl label node k8s-node1 type=node1
kubectl get nodes --show-labels
[[email protected] Tools]# kubectl get nodes --show-labels
NAME         STATUS   ROLES    AGE   VERSION   LABELS
k8s-master   Ready    master   37d   v1.15.3   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/master=,type=master
k8s-node1    Ready    <none>   37d   v1.15.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node1,kubernetes.io/os=linux,type=node1
k8s-node2    Ready    <none>   37d   v1.15.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node2,kubernetes.io/os=linux,type=node2

②将pod分配到带有指定label的node

Pod操作:
删除Pod

kubectl delete pod hello

更新Pod

kubctl replace hello-world.yaml

三、可能遇到的问题

Error:Back-off restarting failed container

[[email protected] Tools]# kubectl describe pod hello-world
Name:         hello-world
Namespace:    default
Priority:     0
Node:         k8s-node1/10.0.2.15
Start Time:   Fri, 18 Oct 2019 17:16:13 +1100
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           192.168.1.15
Containers:
  hello:
    Container ID:  docker://ae85d78070dc02a19fed619c6270732cd98bfc1d824262b2935bc2362d7b70e5
    Image:         ubuntu:14.04
    Image ID:      docker-pullable://[email protected]:2f7c79927b346e436cc14c92bd4e5bd778c3bd7037f35bc639ac1589a7acfa90
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/echo
      Hello
      world
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 18 Oct 2019 17:18:10 +1100
      Finished:     Fri, 18 Oct 2019 17:18:10 +1100
    Ready:          False
    Restart Count:  4
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-hctt8 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-hctt8:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-hctt8
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  type=node1
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                  From                Message
  ----     ------     ----                 ----                -------
  Normal   Scheduled  2m31s                default-scheduler   Successfully assigned default/hello-world to k8s-node1
  Normal   Pulling    2m30s                kubelet, k8s-node1  Pulling image "ubuntu:14.04"
  Normal   Pulled     2m10s                kubelet, k8s-node1  Successfully pulled image "ubuntu:14.04"
  Normal   Created    34s (x5 over 2m10s)  kubelet, k8s-node1  Created container hello
  Normal   Started    34s (x5 over 2m9s)   kubelet, k8s-node1  Started container hello
  Normal   Pulled     34s (x4 over 2m8s)   kubelet, k8s-node1  Container image "ubuntu:14.04" already present on machine
  Warning  BackOff    34s (x9 over 2m7s)   kubelet, k8s-node1  Back-off restarting failed container

解决方法:
As per Describe Pod command listing, your Container inside the Pod has been already completed with exit code 0, which states about successful completion without any errors/problems, but the life cycle for the Pod was very short. To keep Pod running continuously you must specify a task that will never finish.

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]

参考链接:
将pod分配到指定的节点.
Back-off restarting failed container.

原文地址:https://www.cnblogs.com/wucaiyun1/p/11698320.html

时间: 2024-10-02 10:59:45

【Kubernetes】创建Pod并分配到指定节点Node1的相关文章

Kubernetes创建pod一直处于ContainerCreating排查和解决

用k8s创建完pod后,发现无法访问demo应用,查了一下pods状态,发现都在containercreationg状态中. 百度了一下,根据网上的方法,查了一下mysql-jn6f2这个pods的详情 其中最主要的问题是:details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory) 解决方案: 查看/etc/docker/certs.d/regist

kubernetes 创建pod 启动不了 处于ContainerCreating状态

kubectl describe pod my-nginx-379829228-c5g9f for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (Get https:

Docker Kubernetes 创建管理 Pod

Docker Kubernetes 容器扩容与缩容 环境: 系统:Centos 7.4 x64 Docker版本:18.09.0 Kubernetes版本:v1.8 管理节点:192.168.1.79 工作节点:192.168.1.78 工作节点:192.168.1.77 管理节点:创建pod yaml文件 vim pod.yaml apiVersion: v1 kind: Pod metadata: name: pod-test labels: os: centos spec: contain

JS创建一个元素节点, 并把该节点添加为文档中指定节点的子节点

1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <titl

kubernetes 将pod运行在某些特定的节点上,给节点打标签

给节点打上标签: kubectl label node  <node_name> GPU=true   #打上标签 GPU=true 在创建pod的yaml文件时:  添加 nodeSelector 这样pod会在有标签 GPU=true 的node上面运行 原文地址:https://www.cnblogs.com/kuku0223/p/10346201.html

Kubernetes之Pod的生命周期

目录 Kubernetes之Pod的生命周期 理解Pod Pod内如何管理多个容器 Pod的使用 其他替代选择 Pod的持久性 Pod的终止 Init容器 Pause容器 Pod的生命周期 Pod的phase Pod的状态 容器探针 存活性探测 livenessProbe 就绪性探测 readnessProbe livenessProbe和readinessProbe使用场景 lifecycle Kubernetes之Pod的生命周期 理解Pod Pod是kubernetes中你可以创建和部署的

kubernetes之pod超详细解读--第一篇(三)

   小编在这里向各位博友道个歉,上篇文章确实写的有些应付,但怎么说,部署确实因人而异,而且很少有刚刚进公司就让你搭建一个集群,一般公司都有自己的集群,所以小编觉得,侧重点不应该在安装,应该在维护!虽然有些牵强,但小编保证,这一篇绝对有质量!希望看了小编的博客,大家对pod有更深入的认识.   这篇文章,小编打算介绍关于pod的11个重要的知识点,大家要有耐心的看下去哦!虽然内容比较多,有兴趣的朋友可以细细阅读,小编会尽可能的用比较容易理解的话和图,去介绍比较重要并且难以理解的地方. 1. po

kubernetes之pod超详细解读--第二篇(三)

8.资源对象对pod的调度 ??在kubernetes集群中,pod基本上都是容器的载体,通常需要通过相应的资源对象来完成一组pod的调度和自动控制功能,比如:deployment.daemonSet.RC.Job等等.接下来小编将一一介绍这些资源对象如何调度pod. (1)Deployment/RC 自动化调度 ??Deployment/RC的主要功能之一就是自动部署一个容器应用的多个副本,以及持续监控副本数量,在集群内始终维持用户指定的副本数量.举例:(这里以deployment为例) ap

Kubernetes之Pod控制器,ReplicaSet,Deployment,DaemonSet

目录 Kubernetes之Pod控制器,ReplicaSet,Deployment,DaemonSet ReplicaSet Deployment控制器 创建Deployment Deployment更新 Deployment扩容 金丝雀发布 Deployment回滚 DaemonSet 定义 DaemonSet演示 redis-filebeat DaemonSet的滚动更新 Kubernetes之Pod控制器,ReplicaSet,Deployment,DaemonSet Kubernete