k8s-启动单机etcd
1. yml文件
创建etcd.yml文件,内容如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: etcd
namespace: etcd01
spec:
replicas: 1
selector:
matchLabels:
app: etcd
template:
metadata:
labels:
app: etcd
spec:
containers:
- name: gateway
image: quay.io/coreos/etcd:v3.4.13
imagePullPolicy: IfNotPresent
env:
- name: ETCDCTL_API
value: "3"
value: "http://0.0.0.0:2379"
- name: ETCD_LISTEN_CLIENT_URLS
value: "http://0.0.0.0:2379"
ports:
- containerPort: 2379
protocol: TCP
name: tcp01
- containerPort: 2380
protocol: TCP
name: tcp02
volumeMounts:
- mountPath: /etcd
name: etcd-etcd
- mountPath: /etcd-server.etcd
name: etcd-data
volumes:
- name: etcd-etcd
persistentVolumeClaim:
claimName: etcd-etcd
- name: etcd-data
persistentVolumeClaim:
claimName: etcd-data
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: etcd-etcd
namespace: etcd01
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: etcd-data
namespace: etcd01
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Gi
---
kind: Service
apiVersion: v1
metadata:
name: etcd
namespace: etcd01
labels:
name: etcd
spec:
ports:
- name: etcd-01
protocol: TCP
targetPort: 2379
port: 2379
- name: etcd-02
protocol: TCP
targetPort: 2380
port: 2380
selector:
app: etcd
2. 创建服务
# kubectl create namespace etcd
# kubectl create -f etcd.yml
3. 查看结果
- 工作负载和服务
[root@master-01 ~]# kubectl get all -n etcd
NAME READY STATUS RESTARTS AGE
pod/etcd-846f796c66-t5qjl 1/1 Running 0 95d
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/etcd NodePort 172.21.7.113 <none> 2379:31020/TCP,2380:31021/TCP 95d
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/etcd 1/1 1 1 95d
NAME DESIRED CURRENT READY AGE
replicaset.apps/etcd-846f796c66 1 1 1 95d
- 存储
[root@master-01 ~]# kubectl get pvc -n etcd
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
etcd-data Bound nas-c154bc16-2497-44a7-8640-ed0cd590f10f 50Gi RWX alicloud-nas-subpath 95d
etcd-etcd Bound nas-d2b27b9d-99f5-41dd-afcf-6d07e93035ef 10Gi RWX alicloud-nas-subpath 95d