kubernetes运行应用1之Deployment详解

 

查看daemonset

如下,k8s自身的 DaemonSet kube-flannel-ds和kube-proxy分别负责在每个结点上运行flannel和kube-proxy组件
daemonset在每个节点上最多只能运行一个副本。

[machangwei@mcwk8s-master ~]$ kubectl get daemonset
No resources found in default namespace.
[machangwei@mcwk8s-master ~]$ kubectl get daemonset --namespace=kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
kube-flannel-ds 3 3 1 3 1 <none> 5d
kube-proxy 3 3 3 3 3 kubernetes.io/os=linux 5d
[machangwei@mcwk8s-master ~]$ kubectl get pod --namespace=kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-6d8c4cb4d-cnj2t 1/1 Running 0 5d 10.244.0.2 mcwk8s-master <none> <none>
coredns-6d8c4cb4d-ngfm4 1/1 Running 0 5d 10.244.0.3 mcwk8s-master <none> <none>
etcd-mcwk8s-master 1/1 Running 0 5d 10.0.0.4 mcwk8s-master <none> <none>
kube-apiserver-mcwk8s-master 1/1 Running 1 (13h ago) 5d 10.0.0.4 mcwk8s-master <none> <none>
kube-controller-manager-mcwk8s-master 1/1 Running 5 (80m ago) 5d 10.0.0.4 mcwk8s-master <none> <none>
kube-flannel-ds-cn4m9 0/1 CrashLoopBackOff 147 (3m51s ago) 12h 10.0.0.6 mcwk8s-node2 <none> <none>
kube-flannel-ds-hpgkz 1/1 Running 0 5d 10.0.0.4 mcwk8s-master <none> <none>
kube-flannel-ds-nnjvj 0/1 CrashLoopBackOff 185 (3m38s ago) 5d 10.0.0.5 mcwk8s-node1 <none> <none>
kube-proxy-92g5c 1/1 Running 0 12h 10.0.0.6 mcwk8s-node2 <none> <none>
kube-proxy-kk22j 1/1 Running 0 5d 172.16.0.5 mcwk8s-node1 <none> <none>
kube-proxy-xjjgf 1/1 Running 0 5d 10.0.0.4 mcwk8s-master <none> <none>
kube-scheduler-mcwk8s-master 1/1 Running 5 (82m ago) 5d 10.0.0.4 mcwk8s-master <none> <none>
[machangwei@mcwk8s-master ~]$

学习kube-flannel-ds

截取部分:https://www.cnblogs.com/machangwei-8/p/15759077.html#_label7

apiVersion: apps/v1
kind: DaemonSet #语法结构和Deployment几乎往前一样,只是将kind设为DaemonSet
metadata:
name: kube-flannel-ds
namespace: kube-system
labels:
tier: node
app: flannel
spec:
selector:
matchLabels:
app: flannel
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true #指定Pod直接使用的是Node网络,相当于docker run --network=host。
#考虑到flannel需要为集群提供网络连接,这个要求是合理的
initContainers:#定义了运行flannel服务的两个容器
- name: install-cni-plugin
image: rancher/mirrored-flannelcni-flannel-cni-plugin:v1.0.0
command:
containers: #定义了运行flannel服务的两个容器
- name: kube-flannel
image: quay.io/coreos/flannel:v0.15.1
command:
- /opt/bin/flanneld
args:
- --ip-masq
- --kube-subnet-mgr

学习kube-proxy,查看daemonset配置

[machangwei@mcwk8s-master ~]$ kubectl edit daemonset kube-proxy --namespace=kube-system

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: apps/v1
kind: DaemonSet #指定资源类型
metadata:
annotations:
deprecated.daemonset.template.generation: "1"
creationTimestamp: "2022-01-12T15:15:18Z"
generation: 1
labels:
k8s-app: kube-proxy
name: kube-proxy
namespace: kube-system
resourceVersion: "18274"
uid: 04cfea8d-94b3-4963-b8d2-b10a7b6a46b0
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: kube-proxy
template:
metadata:
creationTimestamp: null
labels:
k8s-app: kube-proxy
spec:
containers:
- command:
- /usr/local/bin/kube-proxy
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: apps/v1
kind: DaemonSet #指定资源类型
metadata:
annotations:
deprecated.daemonset.template.generation: "1"
creationTimestamp: "2022-01-12T15:15:18Z"
generation: 1
labels:
k8s-app: kube-proxy
name: kube-proxy
namespace: kube-system
resourceVersion: "18274"
uid: 04cfea8d-94b3-4963-b8d2-b10a7b6a46b0
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: kube-proxy
template:
metadata:
creationTimestamp: null
labels:
k8s-app: kube-proxy
spec:
containers: #定义kube-proxy的容器
- command:
- /usr/local/bin/kube-proxy
- --config=/var/lib/kube-proxy/config.conf
- --hostname-override=$(NODE_NAME)
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
image: registry.aliyuncs.com/google_containers/kube-proxy:v1.23.1
imagePullPolicy: IfNotPresent
name: kube-proxy
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/kube-proxy
name: kube-proxy
- mountPath: /run/xtables.lock
name: xtables-lock
- mountPath: /lib/modules
name: lib-modules
readOnly: true
dnsPolicy: ClusterFirst
hostNetwork: true
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-node-critical
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: kube-proxy
serviceAccountName: kube-proxy
terminationGracePeriodSeconds: 30
tolerations:
- operator: Exists
volumes:
- configMap:
defaultMode: 420
name: kube-proxy
name: kube-proxy
- hostPath:
path: /run/xtables.lock
type: FileOrCreate
name: xtables-lock
- hostPath:
path: /lib/modules
type: ""
name: lib-modules
updateStrategy:
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
status: #当前DamonSet的运行状态,这个部分是kubectl edit 特有的。其实kubernetes集群中每个当前运行的资源都
currentNumberScheduled: 3 #可以通过kubectl edit 查看器配置和运行状态,
desiredNumberScheduled: 3 #比如: kubectl edit deployment mcwnginx-deployment
numberAvailable: 3
numberMisscheduled: 0
numberReady: 3
observedGeneration: 1
updatedNumberScheduled: 3 [machangwei@mcwk8s-master ~]$ kubectl edit daemonset kube-proxy --namespace=kube-system #跟vim一样,q退出,如果修改了那么应该是wq吧
Edit cancelled, no changes made.

运行自己的DaemonSet失败

有时间再看这个失败问题,如果哪位大佬知道,指点下也好

[machangwei@mcwk8s-master ~]$ vim mcwJiankong.yml
[machangwei@mcwk8s-master ~]$ cat mcw
cat: mcw: No such file or directory
[machangwei@mcwk8s-master ~]$ cat mcw
mcwJiankong.yml mcwNginx.yml
[machangwei@mcwk8s-master ~]$ cat mcwJiankong.yml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: mcw-prometheus-node-daemonset
spec:
replicas: 3
selector:
matchLabels:
app: mcw_prometheus
template:
metadata:
labels:
app: mcw_prometheus
spec:
hostNetwork: true
containers:
- name: mcw-pr-node
image: prom/node-exporter
imagePullPolicy: IfNotPresent
command:
- /bin/node_exporter
- --pathprocfs
- /host/proc
- --path.sysfs
- /host/sys
- --collector.filesystem.ignored-mount-points
- ^/(sys|proc|dev|host|etc)($|/)
volumeMounts:
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: root
mountPath: /rootfs
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcwJiankong.yml #daemonset不能指定副本数量,好像每个节点都会运行,这里可能没包括主节点
error: error validating "mcwJiankong.yml": error validating data: ValidationError(DaemonSet.spec): unknown field "replicas" in io.k8s.api.apps.v1.DaemonSetSpec; if you choose to ignore these errors, turn validation off with --validate=false
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ vim mcwJiankong.yml
[machangwei@mcwk8s-master ~]$ cat mcwJiankong.yml #去掉副本数
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: mcw-prometheus-node-daemonset
spec:
selector:
matchLabels:
app: mcw_prometheus
template:
metadata:
labels:
app: mcw_prometheus
spec:
hostNetwork: true
containers:
- name: mcw-pr-node
image: prom/node-exporter
imagePullPolicy: IfNotPresent
command:
- /bin/node_exporter
- --pathprocfs
- /host/proc
- --path.sysfs
- /host/sys
- --collector.filesystem.ignored-mount-points
- ^/(sys|proc|dev|host|etc)($|/)
volumeMounts:
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: root
mountPath: /rootfs
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcwJiankong.yml
daemonset.apps/mcw-prometheus-node-daemonset created
[machangwei@mcwk8s-master ~]$ kubectl get daemonset #查看daemonset
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
mcw-prometheus-node-daemonset 2 2 0 2 0 <none> 19s
[machangwei@mcwk8s-master ~]$ kubectl get pod -o wide #查看pod,结果未能成功运行。不清楚原因,有时间再看这个问题
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mcw-prometheus-node-daemonset-cv8k2 0/1 CrashLoopBackOff 2 (17s ago) 60s 10.0.0.5 mcwk8s-node1 <none> <none>
mcw-prometheus-node-daemonset-z2vvc 0/1 Error 2 (30s ago) 60s 10.0.0.6 mcwk8s-node2 <none> <none>
[machangwei@mcwk8s-master ~]$ kubectl describe pod mcw-prometheus-node-daemonset-cv8k2
Name: mcw-prometheus-node-daemonset-cv8k2
Namespace: default
Priority: 0
Node: mcwk8s-node1/10.0.0.5
Start Time: Tue, 18 Jan 2022 00:34:32 +0800
Labels: app=mcw_prometheus
controller-revision-hash=7b99d77578
pod-template-generation=1
Annotations: <none>
Status: Running
IP: 10.0.0.5
IPs:
IP: 10.0.0.5
Controlled By: DaemonSet/mcw-prometheus-node-daemonset
Containers:
mcw-pr-node:
Container ID: docker://7ff049b0c303ebb997c4794c9ffadbe7520f8cfdba71caec3b6b32c193ea1369
Image: prom/node-exporter
Image ID: docker-pullable://prom/node-exporter@sha256:f2269e73124dd0f60a7d19a2ce1264d33d08a985aed0ee6b0b89d0be470592cd
Port: <none>
Host Port: <none>
Command:
/bin/node_exporter
--pathprocfs
/host/proc
--path.sysfs
/host/sys
--collector.filesystem.ignored-mount-points
^/(sys|proc|dev|host|etc)($|/)
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Tue, 18 Jan 2022 00:36:24 +0800
Finished: Tue, 18 Jan 2022 00:36:24 +0800
Ready: False
Restart Count: 4
Environment: <none>
Mounts:
/host/proc from proc (rw)
/host/sys from sys (rw)
/rootfs from root (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-w9bkl (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
proc:
Type: HostPath (bare host directory volume)
Path: /proc
HostPathType:
sys:
Type: HostPath (bare host directory volume)
Path: /sys
HostPathType:
root:
Type: HostPath (bare host directory volume)
Path: /
HostPathType:
kube-api-access-w9bkl:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/disk-pressure:NoSchedule op=Exists
node.kubernetes.io/memory-pressure:NoSchedule op=Exists
node.kubernetes.io/network-unavailable:NoSchedule op=Exists
node.kubernetes.io/not-ready:NoExecute op=Exists
node.kubernetes.io/pid-pressure:NoSchedule op=Exists
node.kubernetes.io/unreachable:NoExecute op=Exists
node.kubernetes.io/unschedulable:NoSchedule op=Exists
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m36s default-scheduler Successfully assigned default/mcw-prometheus-node-daemonset-cv8k2 to mcwk8s-node1
Normal Pulling 2m36s kubelet Pulling image "prom/node-exporter"
Normal Pulled 2m9s kubelet Successfully pulled image "prom/node-exporter" in 27.526626918s
Normal Created 45s (x5 over 2m9s) kubelet Created container mcw-pr-node
Normal Started 45s (x5 over 2m8s) kubelet Started container mcw-pr-node
Normal Pulled 45s (x4 over 2m8s) kubelet Container image "prom/node-exporter" already present on machine
Warning BackOff 31s (x9 over 2m7s) kubelet Back-off restarting failed container
[machangwei@mcwk8s-master ~]$

kubernetes运行应用2之DaemonSet详解的更多相关文章

  1. Kubernetes K8S之资源控制器Daemonset详解

    Kubernetes的资源控制器Daemonset详解与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7.7 2C/ ...

  2. [Spark内核] 第36课:TaskScheduler内幕天机解密:Spark shell案例运行日志详解、TaskScheduler和SchedulerBackend、FIFO与FAIR、Task运行时本地性算法详解等

    本課主題 通过 Spark-shell 窥探程序运行时的状况 TaskScheduler 与 SchedulerBackend 之间的关系 FIFO 与 FAIR 两种调度模式彻底解密 Task 数据 ...

  3. [Spark内核] 第40课:CacheManager彻底解密:CacheManager运行原理流程图和源码详解

    本课主题 CacheManager 运行原理图 CacheManager 源码解析 CacheManager 运行原理图 [下图是CacheManager的运行原理图] 首先 RDD 是通过 iter ...

  4. Docker Kubernetes Service 网络服务代理模式详解

    Docker Kubernetes  Service 网络服务代理模式详解 Service service是实现kubernetes网络通信的一个服务 主要功能:负载均衡.网络规则分布到具体pod 注 ...

  5. Kubernetes K8S之资源控制器StatefulSets详解

    Kubernetes的资源控制器StatefulSet详解与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7.7 2 ...

  6. Kubernetes K8S之调度器kube-scheduler详解

    Kubernetes K8S之调度器kube-scheduler概述与详解 kube-scheduler调度概述 在 Kubernetes 中,调度是指将 Pod 放置到合适的 Node 节点上,然后 ...

  7. Kubernetes K8S之鉴权RBAC详解

    Kubernetes K8S之鉴权概述与RBAC详解 K8S认证与授权 认证「Authentication」 认证有如下几种方式: 1.HTTP Token认证:通过一个Token来识别合法用户. H ...

  8. 基于kubernetes构建Docker集群管理详解-转

    http://blog.liuts.com/post/247/ 一.前言        Kubernetes 是Google开源的容器集群管理系统,基于Docker构建一个容器的调度服务,提供资源调度 ...

  9. Kubernetes笔记(四):详解Namespace与资源限制ResourceQuota,LimitRange

    前面我们对K8s的基本组件与概念有了个大致的印象,并且基于K8s实现了一个初步的CI/CD流程,但对里面涉及的各个对象(如Namespace, Pod, Deployment, Service, In ...

随机推荐

  1. java IO操作和计算操作:工作内存和主内存 volatile关键字作用;原子操作对象AtomicInteger ....

    应该停止但无法停止的计算线程 如下线程示例,线程实例中while循环中的条件,在主线程中通过调用实例方法更新后,while循环并没有更新判断变量是否还成立.而是陷入了while(true)死循环. i ...

  2. java 多线程:Thread类常用方法:setPriority优先级、interrupt中断标记、suspend暂停与唤醒resume(已过时);daemon守护线程

    常用方法: boolean isAlive() 测试此线程是否存活. boolean isDaemon() 测试此线程是否为守护程序线程. static void sleep?(long millis ...

  3. JavaScript扫盲笔记:

    JavaScript学习: JavaScript代码存在形式: -Head中 <script> </script> -文件 <script src='代码所在路径'> ...

  4. JAVA微信支付——微信公众号内支付 代码

    官方文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1 微信PC二维码支付方式参考:https://www.cnblogs. ...

  5. SpringBoot 自定义注解

    新增注解类 NotRepeatSubmit.java package com.example.demo.annotation; import java.lang.annotation.ElementT ...

  6. Linux C(++)获取可执行程序完整路径

    代码 #include <sys/statfs.h> #include <string> #include <iostream> #include <limi ...

  7. 【LeetCode】366. Find Leaves of Binary Tree 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcod ...

  8. C. Success Rate

    Success Rate 题目链接 题意 给你两个分数形式的数,然后有两种变化方式 上下都+1 仅下面部分+1 让你求第一个分数变化到第二个分数的最小步数. 思路 有几种特殊情况分类讨论一下. 首先我 ...

  9. ZOJ 3778:Talented Chef(贪心?思维)

    Talented Chef Time Limit: 2 Seconds Memory Limit: 65536 KB As we all know, Coach Gao is a talented c ...

  10. element 表格只展开一行(点击下一行上一行关闭)

    源码:第一步 <el-table :data="tableData" border :row-class-name="tableRowClassName" ...