Skip to content

Commit

Permalink
Update Kubernetes.md
Browse files Browse the repository at this point in the history
Add StatefulSet yaml example
  • Loading branch information
BinL233 authored Jun 16, 2023
1 parent 74e5b92 commit 0a16f08
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion kubernetes/Kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,63 @@ StatefulSet是为了解决**有状态服务**的问题(对应Deployments和Rep

*有状态服务需要在本地存储持久化数据,典型的是分布式数据库的应用,分布式节点实例之间有依赖的拓扑关系.比如,主从关系. 如果K8S停止分布式集群中任 一实例pod,就可能会导致数据丢失或者集群的crash.*

**创建StatefulSet**

*下面例子由StatefulSet创建了3个pod来启动Nginx并创建了 Headless Service 用来控制网络域名*

*注:Headless Service 不会分配负载均衡IP地址*
```
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # 必须匹配 .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # 默认值是 1
minReadySeconds: 10 # 默认值是 0
template:
metadata:
labels:
app: nginx # 必须匹配 .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi
```

## Service

### 1. Service
Expand Down Expand Up @@ -540,4 +597,4 @@ metadata常用的配置项有 name,namespace,即配置其显示的名字与归
1. https://kubernetes.io/zh-cn/docs/home/
2. https://jimmysong.io/kubernetes-handbook/concepts/
3. https://www.cnblogs.com/caodan01/p/15102328.html
4. https://juejin.cn/post/7107251448034885639、
4. https://juejin.cn/post/7107251448034885639、

0 comments on commit 0a16f08

Please sign in to comment.