Kubernetes SatefulSet (stateful application deployment)

Kubernetes SatefulSet (stateful application deployment)

• deployment of stateful application
• solve Pod independent life cycle, to maintain order and uniqueness Pod start
1. stable, unique network identifier, persistent storage
2., orderly and elegant deployment and expansion, delete and end
3. orderly, rolling updates

Scenario: Database

Explanation

Conventional Service
Service: a pod set access policies to provide load balancing and service discovery
other: service assigns a CLUSTER-IP virtual IP to communicate the entire container.

headless service: service headless
headless service: service and similar, except that clusterIP to None

You need to deploy a dns server
vim coredns.yaml
------------
*** slightly
------------

Case

Create a stateful application
1, vim sts.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx

---

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: nginx-statefulset
  namespace: default
spec:
  # 指定使用的service
  serviceName: nginx
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

2, create a container

kubectl create -f sts.yaml

3, create a container view and service, by dns name, to ensure that each fixed identity (pod / nginx-statefulset-x ) logo.
kubectl get pods, svc

NAME READY STATUS RESTARTS AGE
# statefulset-x 为身份标识
pod/nginx-statefulset-0 1/1 Running 0 16s
pod/nginx-statefulset-1 1/1 Running 0 13s
pod/nginx-statefulset-2 1/1 Running 0 10s
pod/sh-77649dbd59-ppfbx 1/1 Running 0 21m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 5d16h
service/nginx ClusterIP None <none> 80/TCP 26s

4, temporarily start the test program resolved by dns resolution that uniquely identifies the container
kubectl run --image = busybox: 1.28.4 -it sh

/ # nslookup nginx-statefulset-0
Server:    10.0.0.2
Address 1: 10.0.0.2 kube-dns.kube-system.svc.cluster.local

nslookup: can't resolve 'nginx-statefulset-0'

So you can compare the effect

StatefulSet differs Deployment: identity of!
The identity of three elements:
• domain name
• host name
• Storage (PVC)

ClusterIP A recording format: <-Service-name> <namespace-name> .svc.cluster.local.
ClusterIP = None A recording format:. <StatefulsetName-index> < service-name> .svc.cluster.local
Example: web- 0.nginx.default.svc.cluster.local


 

Guess you like

Origin www.cnblogs.com/xiangsikai/p/11424078.html