docker pull registry.aliyuncs.com/google_containers/nginx-slim:0.8
docker tag registry.aliyuncs.com/google_containers/nginx-slim:0.8 k8s.gcr.io/nginx-slim:0.8
docker rmi registry.aliyuncs.com/google_containers/nginx-slim:0.8
使用集群默认自带的 StorageClass
kubectl get storageclass
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
hostpath (default) docker.io/hostpath Delete Immediate false 14d
kubectl apply -f nginx-statefulset-and-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx # 无头服务 name
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None # 无头服务(Headless Services),负责 Pod 稳定的、唯一的网络标识
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: nginx # 无头服务 name
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates: # 没有指定 StorageName,则使用集群默认的存储类
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi