最近尝试学了一下K8S,感觉还行吧!只是对于我自己的项目来说还没必要,弄个docker就不错了,集群对于小项目来说部署有点夸张。个人看了这几天发现官方的交互式教程还是挺爽的,简单了解还是可行的。我这就弄个从头到尾的单节点部署让大家了解一下,可能稍微有点乱。
- 官方教程:https://kubernetes.io/zh/docs/home/
- 安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
- 注意非root用户操作的授权,这里以emperinter用户为例
sudo usermod -aG docker emperinterk8s相关组件安装
- 安装minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
- 安装kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl chmod +x kubectl sudo mv ./kubectl /usr/local/bin/kubectl操作
获取镜像这里以2个pod为例,操作用户非root用户
docker pull wiznote/wizserver启动环境
- 启动minikube
mount可以参考配置 Pod 以使用 PersistentVolume 作为存储
minikube start --mount --mount-string="/mnt/data:/app/wiz"
- 查看
minikube ssh
- 启动dashboard
minikube dashboard
- dashboard地址总是改变,如需想固定端口的话,可以使用
nohup minikube dashboard >> dashboard.log 2>&1 & nohup kubectl proxy --port=8080 --address=0.0.0.0 --accept-hosts='^*$' >> proxy.log 2>&1 &部署 命令行部署
这个方式不推荐,有许多东西都需要配置
kubectl create deployment wiz --image=wiznote/wizserver:latest配置文件部署
-
创建PVC存储,具体参考:https://www.emperinter.info/2022/04/18/configure-persistent-volume-storage/
-
创造配置文件:wiz.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: wiz #Deployment名称
labels:
app: wiz
spec:
replicas: 2 #目标副本数量
selector:
matchLabels:
app: wiz
template:
metadata:
labels:
app: wiz
spec:
volumes:
- name: wiz-pv-storage
persistentVolumeClaim:
claimName: wiz-pv-claim #PVC 存储名称
containers:
- name: wizserver
image: wiznote/wizserver:latest
resources: {}
imagePullPolicy: Always
volumeMounts: #容器内挂载点
- mountPath: "/wiz/storage/"
name: wiz-pv-storage #必须有名称
ports: #定义端口
- name: container-port #定义pod名称
containerPort: 80 #定义pod端口
protocol: TCP #定义TCP
restartPolicy: Always
terminationGracePeriodSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
- 用配置文件部署
kubectl create -f wiz.yaml
如需了解网络配置以及更多请访问:https://www.emperinter.info/2022/04/20/k8s-single-node-deployment/



