其他分享
首页 > 其他分享> > 六、k8s入门系列----StatefulSet、Headless Services、LoadBalancer Services

六、k8s入门系列----StatefulSet、Headless Services、LoadBalancer Services

作者:互联网

  这节讲下 有状态服务应用 StatefulSet 和另外两种 Service:Headless  和 LoadBalancer 。

  应用的状态有如下定义:

  有状态应用关键点是可以复用原来的数据,而无状态应用每次都是新的状态。

  Deployment 和 StatefulSet 分别应用于无状态服务应用和有状态服务应用,StatefulSet 常见的应用场景:

  编写statefulset 资源配置文件,其中serviceName 为必填字段,关联一个Headless Service,其他配置跟deployment大同小异:

[root@ylserver10686071 ~]# cat statefulset.yml 
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: stateapp
  namespace: prod
spec:
  serviceName: stateapp-svc
  selector:
    matchLabels:
      k8s-app: stateapp
  replicas: 3
  template:
    metadata:
      labels:
        k8s-app: stateapp
    spec:
      containers:
      - name: stateapp
        image: tomcat:8.0
        ports:
        - name: stateapp-8080
          containerPort: 8080
          protocol: TCP

  创建statefulset资源,并查看相关信息,可以看到 Pod 的名称是按照顺序命名的,不是随机生成的:

[root@ylserver10686071 ~]# kubectl apply -f statefulset.yml 
statefulset.apps/stateapp created
[root@ylserver10686071 ~]# kubectl get statefulset -n prod -o wide
NAME       READY   AGE   CONTAINERS   IMAGES
stateapp   3/3     63s   stateapp     tomcat:8.0
[root@ylserver10686071 ~]# kubectl get pods -n prod -o wide |grep stateapp
stateapp-0                      1/1     Running   0          60s   10.233.72.43   ylserver10686073   <none>           <none>
stateapp-1                      1/1     Running   0          48s   10.233.67.38   ylserver10686072   <none>           <none>
stateapp-2                      1/1     Running   0          33s   10.233.75.66   ylserver10686071   <none>           <none>
[root@ylserver10686071 ~]# 

  

标签:StatefulSet,stateapp,----,statefulset,应用,Services,root,ylserver10686071
来源: https://www.cnblogs.com/fenggq/p/15038700.html