Notes of "Kubernetes in Actions" - Statefulset

StatefulSet介绍 StatefulSet特点: 每个Pod拥有一个唯一确定的身份标识 StatefulSet确保不会有两个同样标识的pod存在(at-most-one) StatefulSet需要每个Pod都创建一个headless Service,用于给pod提供DNS解析,hostname格式为: <pod-name>.<service-name>.default.svc.cluster.local Scaling StatefulSet Scaling down 每次减少StatefulSet的replica数量时,都可以预知哪个pod被减少,例如SS有3个replica,分别为:pod-0, pod-1, pod-2,如果replica减少为2,则首先会删除pod-2;如果replica减少为1,则继续会删除pod-1。 ...

October 16, 2023

Setup K8s with Aliyun ECS

This article will try to explain how to setup a k8s cluster with three nodes with aliyun ecs. 1. Environment Aliyun ECS with Ubuntu 22.04 2 cores + 4G ECS Docker 24.0.6 Server has been install docker + containerd Because containerd installed with docker, so we can use conatainerd as the runtime of k8s, but we need to enable CRI interface in containerd. 2. Init MASTER NODE add apt source ...

October 16, 2023

Notes of "Kubernetes in Actions" - Volumes

Volume 是依赖于Pod而存在的对象,不能单独被创建,pod的volume对pod的所有容器都可见。 Volume简介 Volume类型 emptyDir 用于存储透明的数据(随着pod被移除而移除) hostPath 使用宿主机的文件系统作为volume gitRepo 使用git仓库作为volume nfs 使用NFS文件系统 gcePersistentDisk/awsElasticBlockStore/azureDisk 使用GCE/AWS/Azure的磁盘 cinder/cephfs/iscsi 使用网络存储系统 configMap/secret/downwardAPI 使用k8s的特殊对象作为volume persistentVolumeClaim 动态创建文件系统 使用Volumes在容器间共享数据 emptyDir volume gitRepo volume hostPath volume pod与底层存储的解耦 PersistentVolumes和PersistentVolumeClaims 创建PV apiVersion: v1 kind: PersistentVolume metadata: name: mongodb-pv spec: capacity: storage: 1Gi accessMode: # 一个客户端读写 - ReadWriteOnce # 多个客户端只读 - ReadOnlyMany # PVC被删除后,使用Retain保留PV的策略 persistentVolumeReclaimPolicy: Retain # 底层使用GCE Disk gcePersistentDisk: pdName: mongodb fsType: ext4 通过PVC动态声明创建PV apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mongodb-pvc spec: resources: requests: storage: 1Gi accessModes: # 只允许一个客户端读写 - ReadWriteOnce storageClassName: "" 在Pod中使用PVC apiVersion: v1 kind: Pod metadata: name: mongodb spec: containers: - image: mongo name: mongodb volumeMounts: - name: mongodb-data mountPath: /data/db ports: - containerPort: 27017 protocol: TCP volumes: - name: mongodb-data persistentVolumeClaim: className: mongodb-pvc PV回收 PV的状态分为: ...

October 15, 2023