文章目录
-
- 安装 curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 注意非root用户操作的授权,这里以emperinter用户为例 sudo usermod -aG docker emperinter
- 安装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
-
- minikube ip # 获取minikube的ip地址
-
- 我这用的windwos的wsl,简单转发地址是:http://127.0.0.1:8888/ kubectl port-forward deployment/wiz 8888:80 # 或者 # kubectl port-forward wiz-79b4644f99-447b8 8888:80 # kubectl port-forward service/wiz 8888:80
- shell直接跑 kubectl expose deployment wiz --"type=NodePort" --port=8888 --target-port=80 # 暴露8080端口,类型为NodePort(在每个Node上分配一个端口作为外部访问入口) 也可以创建一个service apiVersion: v1 kind: Service metadata: name: wiz-service spec: type: NodePort selector: app: wiz ports: - protocol: TCP port: 8888 targetPort: 80 kubectl create -f wiz-service.yaml
- kubectl get services/wiz -o go-template='{{(index .spec.ports 0).nodePort}}'
- wiz这个pod部署有点问题,有时候无法访问。 curl -I minikubeIP:
最近尝试学了一下K8S,感觉还行吧!只是对于我自己的项目来说还没必要,弄个docker就不错了,集群对于小项目来说部署有点夸张。个人看了这几天发现官方的交互式教程还是挺爽的,简单了解还是可行的。我这就弄个从头到尾的单节点部署让大家了解一下,可能稍微有点乱。
- 安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
- 注意非root用户操作的授权,这里以emperinter用户为例
sudo usermod -aG docker emperinter
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
sudo usermod -aG docker emperinter
- 安装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
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
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用户
这里以2个pod为例,操作用户非root用户
docker pull wiznote/wizserver
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 &
mount可以参考配置 Pod 以使用 PersistentVolume 作为存储
minikube start --mount --mount-string="/mnt/data:/app/wiz"
minikube ssh
minikube 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
这个方式不推荐,有许多东西都需要配置
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
创造配置文件: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
minikube ip # 获取minikube的ip地址
minikube ip # 获取minikube的ip地址
我这用的windwos的wsl,简单转发地址是:http://127.0.0.1:8888/
kubectl port-forward deployment/wiz 8888:80
# 或者
# kubectl port-forward wiz-79b4644f99-447b8 8888:80
# kubectl port-forward service/wiz 8888:80
我这用的windwos的wsl,简单转发地址是:http://127.0.0.1:8888/
kubectl port-forward deployment/wiz 8888:80
# 或者
# kubectl port-forward wiz-79b4644f99-447b8 8888:80
# kubectl port-forward service/wiz 8888:80
- shell直接跑
kubectl expose deployment wiz --"type=NodePort" --port=8888 --target-port=80 # 暴露8080端口,类型为NodePort(在每个Node上分配一个端口作为外部访问入口)
- 也可以创建一个service
apiVersion: v1
kind: Service
metadata:
name: wiz-service
spec:
type: NodePort
selector:
app: wiz
ports:
- protocol: TCP
port: 8888
targetPort: 80
kubectl create -f wiz-service.yaml
kubectl expose deployment wiz --"type=NodePort" --port=8888 --target-port=80 # 暴露8080端口,类型为NodePort(在每个Node上分配一个端口作为外部访问入口)
apiVersion: v1
kind: Service
metadata:
name: wiz-service
spec:
type: NodePort
selector:
app: wiz
ports:
- protocol: TCP
port: 8888
targetPort: 80
kubectl create -f wiz-service.yaml
kubectl get services/wiz -o go-template='{{(index .spec.ports 0).nodePort}}'
kubectl get services/wiz -o go-template='{{(index .spec.ports 0).nodePort}}'
wiz这个pod部署有点问题,有时候无法访问。
curl -I minikubeIP:
wiz这个pod部署有点问题,有时候无法访问。
curl -I minikubeIP:
kubectl scale deployments/wiz --replicas=8
kubectl scale deployments/wiz --replicas=8
- 查看所有
kuectl get all
- 查看deployment
kubectl get deployment
- 查看pod
kubectl get pods
kuectl get all
kubectl get deployment
kubectl get pods
kubectl exec -it wiz-5c647c8d4f-rq5q8 -- bash
# exit 退出
kubectl exec -it wiz-5c647c8d4f-rq5q8 -- bash
# exit 退出
kubectl logs wiz-5c647c8d4f-rq5q8
kubectl logs wiz-5c647c8d4f-rq5q8
