控制器相关
作者:互联网
StatefulSet
示例文件
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: http
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10 # 默认30秒
containers:
- name: nginx
image: registry.cn-beijing.aliyuncs.com/google_registry/nginx:1.17
ports:
- containerPort: 80
name: http
####### 特点
- StatefulSet为每个Pod副本创建了一个DNS域名,这个域名的格式为:$(podname).(headless service name),也就意味着服务之间是通过Pod域名来通信而非Pod IP。当Pod所在Node发生故障时,Pod会被漂移到其他Node上,Pod IP会发生改变,但Pod域名不会变化
- StatefulSet使用Headless服务来控制Pod的域名,这个Headless服务域名的为:$(service name).$(namespace).svc.cluster.local,其中 cluster.local 指定的集群的域名
- 根据volumeClaimTemplates,为每个Pod创建一个PVC,PVC的命令规则为:$(volumeClaimTemplates name)-$(pod name),比如volumeClaimTemplates为www,pod name为web-0、web-1、web-2;那么创建出来的PVC为:www-web-0、www-web-1、www-web-2
- 删除Pod不会删除对应的PVC,手动删除PVC将自动释放PV
DaemonSet
示例
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: default
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
# 允许在master节点运行
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: registry.cn-beijing.aliyuncs.com/google_registry/fluentd:v2.5.2
resources:
limits:
cpu: 1
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
# 优雅关闭应用,时间设置。超过该时间会强制关闭【可选项】,默认30秒
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
标签:web,控制器,name,fluentd,nginx,相关,Pod,spec 来源: https://www.cnblogs.com/yunwei/p/15230051.html