一、编辑yaml文件###

[root@K8s-Master 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" ]

二、创建并查看运行状态###

[root@K8s-Master Tools]# kubectl create -f hello-world-pod.yaml
pod/hello-world created
[root@K8s-Master Tools]# kubectl get pod hello-world
NAME READY STATUS RESTARTS AGE
hello-world 1/1 Running 0 8m2s
[root@K8s-Master 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分配到指定的节点

将pod调度到指定节点有2种方式:

方式一:强制约束Pod调度到指定Node节点上

Pod.spec.nodeName

方式二:通过label-selector机制选择节点

Pod.spec.nodeSelector





以下使用第二种方式实现pod调度到指定节点。

①为Node添加label

kubectl label node k8s-node1 type=node1
kubectl get nodes --show-labels
[root@K8s-Master 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

[root@K8s-Master 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://ubuntu@sha256: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.

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

  1. [置顶] kubernetes创建资源yaml文件例子--pod

    kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...

  2. pod(一):Kubernetes(k8s)创建pod的两种方式

    目录 一.系统环境 二.前言 三.pod 四.创建pod 4.1 环境介绍 4.2 使用命令行的方式创建pod 4.2.1 创建最简单的pod 4.2.2 创建pod,指定镜像下载策略 4.2.3 创 ...

  3. k8s创建pod流程

    kubernetes 创建Pod 的 工作流: step.1 kubectl 向 k8s api server 发起一个create pod 请求(即我们使用Kubectl敲一个create pod命 ...

  4. K8s创建pod yaml文件详解

    kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...

  5. k8s创建pod和service的过程

    一.概念介绍 更详细的参见:https://www.kubernetes.org.cn/5335.html 1.K8s K8s 是一种用于在一组主机上运行和协同容器化应用程序的系统,提供应用部署.规划 ...

  6. Kubernetes集群向指定节点上创建容器

    如果需要限制Pod到指定的Node上运行,则可以给Node打标签并给Pod配置NodeSelector. 给节点添加标签 首先查看节点信息 [root@k8s-master ~]# kubectl g ...

  7. Docker Kubernetes 创建管理 Pod

    Docker Kubernetes 容器扩容与缩容 环境: 系统:Centos 7.4 x64 Docker版本:18.09.0 Kubernetes版本:v1.8 管理节点:192.168.1.79 ...

  8. kubernetes创建资源对象yaml文件例子--pod详解

    apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 metadata: #资源的元数据/属性 name: ...

  9. Kubernetes对Pod调度指定Node以及Node的Taint 和 Toleration

    由于博客园不支持markdown,推荐以下url阅读: 原创url:https://blog.csdn.net/weixin_42495873/article/details/103364868 ## ...

随机推荐

  1. js错误处理Try-catch和throw

    1.try-catch语句   Try{ //可能会导致错误的代码 }catch(error){ //在错误发生时怎么处理 } 例如: try{ window.someNonexistentFunct ...

  2. 数据人看Feed流-架构实践

    背景 Feed流:可以理解为信息流,解决的是信息生产者与信息消费者之间的信息传递问题.我们常见的Feed流场景有:1 手淘,微淘提供给消费者的首页商品信息,用户关注店铺的新消息等2 微信朋友圈,及时获 ...

  3. HZOJ Silhouette

    转化一下题意:给出矩阵每行每列的最大值,求满足条件的矩阵个数. 先将A,B按从大到小排序,显然没有什么影响.如果A的最大值不等于B的最大值那么无解否则一定有解. 考虑从大到小枚举A,B中出现的数s,那 ...

  4. Java 调用restful webservice & jackson

    package com.bullshit.webcrawler.client.impl; import java.io.BufferedReader; import java.io.IOExcepti ...

  5. mybatis分页插件pageHelper简单实用

    工作的框架spring springmvc mybatis3 首先使用分页插件必须先引入maven依赖,在pom.xml中添加如下 <!-- 分页助手 --> <dependency ...

  6. Mysql 查询一天中每半小时记录的数量

    SELECT HOUR(e.time)as Hour,FLOOR(MINUTE(e.time)/30) as M, COUNT(*) as Count FROM error_log e WHERE e ...

  7. 2019-8-31-dotnet-通过-WMI-获取系统补丁

    title author date CreateTime categories dotnet 通过 WMI 获取系统补丁 lindexi 2019-08-31 16:55:59 +0800 2019- ...

  8. js获取本周日期

    JS获取到本周的日期 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  9. H3C 代理ARP

  10. oracle CBO下使用更具选择性的索引

    基于成本的优化器(CBO, Cost-Based Optimizer)对索引的选择性进行判断来决定索引的使用是否能提高效率. 如果索引有很高的选择性, 那就是说对于每个不重复的索引键值,只对应数量很少 ...