给etcd服务器节点打标签
kubectl get node --show-labels=true
kubectl label nodes k8s-slave3 etcd-server=master
etcd服务器节点创建目录
mkdir -p /home/etcd/data
编辑部署文件etcd.yaml
apiVersion: v1
kind: Namespace
metadata:
name: k8s-etcd
---
apiVersion: v1
kind: Service
metadata:
labels:
app: etcd-cs
name: etcd-cs
namespace: k8s-etcd
spec:
type: NodePort
ports:
- name: tcp-client
port: 2379
targetPort: 2379
nodePort: 30379
selector:
app: etcd
---
apiVersion: v1
kind: Service
metadata:
labels:
app: etcd-hs
name: etcd-hs
namespace: k8s-etcd
spec:
type: ClusterIP
clusterIP: None
publishNotReadyAddresses: true
ports:
- name: tcp-client
port: 2379
targetPort: client
selector:
app: etcd
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: etcd
name: etcd
namespace: k8s-etcd
spec:
serviceName: etcd-hs
replicas: 1
selector:
matchLabels:
app: etcd
template:
metadata:
labels:
app: etcd
spec:
containers:
- name: etcd
env:
- name: ETCD_ENABLE_V2
value: "true"
- name: ALLOW_NONE_AUTHENTICATION
value: "yes"
- name: ETCD_ADVERTISE_CLIENT_URLS
value: "http://0.0.0.0:2379"
- name: ETCD_LISTEN_CLIENT_URLS
value: "http://0.0.0.0:2379"
image: bitnami/etcd:3.5.6
imagePullPolicy: IfNotPresent
ports:
- name: client
containerPort: 2379
volumeMounts:
- name: etcd-data
mountPath: /bitnami/etcd/
volumes:
- name: etcd-data
hostPath:
path: /home/etcd/data/
nodeSelector:
etcd-server: master
执行部署
kubectl apply -f etcd.yaml
查看部署情况
#查看pod
kubectl get pod -n k8s-etcd -o wide
kubectl -n k8s-etcd describe pod etcd-0
kubectl -n k8s-etcd logs etcd-0 --all-containers=true
# 查看域名解析
nslookup etcd-cs.k8s-etcd.svc.cluster.local 172.16.0.10
nslookup etcd-hs.k8s-etcd.svc.cluster.local 172.16.0.10
nslookup etcd-0.etcd-hs.k8s-etcd.svc.cluster.local 172.16.0.10