参考文档:
https://www.minio.org.cn/docs/minio/kubernetes/upstream/index.html
https://anqixiang.blog.csdn.net/article/details/127228195
https://blog.csdn.net/baidu_35848778/article/details/131436354
https://blog.csdn.net/weixin_41957626/article/details/134842954
https://blog.csdn.net/qq_44209563/article/details/134801099
https://www.jianshu.com/p/2d45990dd652
https://blog.csdn.net/anqixiang/article/details/127228195
创建namespace
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl create ns minio-dev
创建配置文件
1zhangcong@lenovo-e47-1no6e7d:~$ vi minio-dev.yaml
内容如下:
1apiVersion: v1
2kind: PersistentVolume
3metadata:
4 labels:
5 app: minio
6 release: minio
7 name: minio
8 namespace: minio-dev
9spec:
10 accessModes:
11 - ReadWriteOnce
12 capacity:
13 storage: 10Gi
14 volumeMode: Filesystem
15 hostPath:
16 path: /home/zhangcong/dev/minio-data
17---
18apiVersion: v1
19kind: PersistentVolumeClaim
20metadata:
21 # This name uniquely identifies the PVC. Will be used in deployment below.
22 name: minio-pv-claim
23 labels:
24 app: minio-storage-claim
25 namespace: minio-dev
26spec:
27 # Read more about access modes here: https://kubernetes.io/docs/user-guide/persistent-volumes/#access-modes
28 accessModes:
29 - ReadWriteOnce
30 resources:
31 # This is the request for storage. Should be available in the cluster.
32 requests:
33 storage: 10Gi
34 # Uncomment and add storageClass specific to your requirements below. Read more https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1
35 #storageClassName:
36---
37apiVersion: apps/v1
38kind: Deployment
39metadata:
40 # This name uniquely identifies the Deployment
41 name: minio-deployment
42 namespace: minio-dev
43spec:
44 strategy:
45 type: Recreate
46 selector:
47 matchLabels:
48 app: minio
49 template:
50 metadata:
51 labels:
52 # Label is used as selector in the service.
53 app: minio
54 spec:
55 # Refer to the PVC created earlier
56 volumes:
57 - name: storage
58 persistentVolumeClaim:
59 # Name of the PVC created earlier
60 claimName: minio-pv-claim
61 containers:
62 - name: minio
63 # Pulls the default MinIO image from Docker Hub
64 image: minio/minio
65 # 注意:--console-address ":5000"用来固定控制台访问端口,否则页面会无法访问控制台
66 command:
67 - /bin/bash
68 - -c
69 args:
70 - minio server /data --console-address :5000 --address :9000
71 env:
72 # MinIO access key and secret key
73 - name: MINIO_ROOT_USER
74 value: "admin"
75 - name: MINIO_ROOT_PASSWORD
76 value: "admin123"
77 ports:
78 - name: data
79 containerPort: 9000
80 protocol: "TCP"
81 - name: console
82 containerPort: 5000
83 protocol: "TCP"
84 # Mount the volume into the pod
85 volumeMounts:
86 - name: storage # must match the volume name, above
87 mountPath: "/data"
88---
89apiVersion: v1
90kind: Service
91metadata:
92 namespace: minio-dev
93 name: minio-service
94
95spec:
96 type: ClusterIP #NodePort
97 ports:
98 - name: data
99 port: 9000
100 targetPort: 9000
101 protocol: TCP
102 #nodePort: 31955 # type=NodePort 时有效
103 - name: console
104 port: 5000
105 targetPort: 5000
106 protocol: TCP
107 #nodePort: 32108 # type=NodePort 时有效
108 selector:
109 app: minio
应用配置
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl apply -f minio-dev.yaml
2persistentvolume/minio created
3persistentvolumeclaim/minio-pv-claim created
4deployment.apps/minio-deployment created
5service
删除
zhangcong@lenovo-e47-1no6e7d:~$ kubectl delete -f minio-dev.yaml
更新
zhangcong@lenovo-e47-1no6e7d:~$ kubectl replace -f minio-dev.yaml
查看启动日志
查看pod运行状态,正常:
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl get pod -o wide -n minio-dev
2NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
3minio-deployment-d68db56cf-jdqmn 1/1 Running 0 9m8s 172.17.0.5 minikube <none> <none>
查看pod运行日志
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl logs -n minio-dev -f minio-deployment-d68db56cf-jdqmn
2MinIO Object Storage Server
3Copyright: 2015-2023 MinIO, Inc.
4License: GNU AGPLv3 https://www.gnu.org/licenses/agpl-3.0.html
5Version: RELEASE.2023-12-23T07-19-11Z (go1.21.5 linux/amd64)
6Status: 1 Online, 0 Offline.
7S3-API: http://172.17.0.5:9000 http://127.0.0.1:9000
8Console: http://172.17.0.5:5000 http://127.0.0.1:5000
9Documentation: https://min.io/docs/minio/linux/index.html
10Warning: The standard parity is set to 0. This can lead to data loss.
根据日志可获取以下信息:
api端口为9000,控制台端口为5000
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl get pvc -o wide -n minio-dev
2NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE
3minio-pv-claim Bound pvc-c4c7207b-97ae-466e-9763-d36063bb3fed 10Gi RWO standard 27m Filesystem
查看svc并访问控制台
1zhangcong@lenovo-e47-1no6e7d:~$ kubectl get svc -o wide -n minio-dev
2NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
3minio-service ClusterIP 10.110.255.174 <none> 9000/TCP,5000/TCP 15h app=minio
1zhangcong@lenovo-e47-1no6e7d:~$ minikube service list
2
3|----------------------|---------------------------|--------------|-----|
4| NAMESPACE | NAME | TARGET PORT | URL |
5|----------------------|---------------------------|--------------|-----|
6| default | kubernetes | No node port | |
7| kube-system | kube-dns | No node port | |
8| kubernetes-dashboard | dashboard-metrics-scraper | No node port | |
9| kubernetes-dashboard | kubernetes-dashboard | No node port | |
10| minio-dev | minio-service | No node port | |
11|----------------------|---------------------------|--------------|-----|
12
13
14zhangcong@lenovo-e47-1no6e7d:~$ kubectl describe services/minio-service -n minio-dev
15Name: minio-service
16Namespace: minio-dev
17Labels: <none>
18Annotations: <none>
19Selector: app=minio
20Type: NodePort
21IP Family Policy: SingleStack
22IP Families: IPv4
23IP: 10.98.82.49
24IPs: 10.98.82.49
25Port: data 9000/TCP
26TargetPort: 9000/TCP
27NodePort: data 31955/TCP
28Endpoints: 172.17.0.4:9000
29Port: console 5000/TCP
30TargetPort: 5000/TCP
31NodePort: console 32108/TCP
32Endpoints: 172.17.0.4:5000
33Session Affinity: None
34External Traffic Policy: Cluster
35Events: <none>
添加转发规则,使其能外部访问:
1# 5000为web控制台端口,9000为api访问端口
2root@lenovo-e47-1no6e7d:~# kubectl port-forward --address 0.0.0.0 -n minio-dev service/minio-service 9090:5000 9000:9000
此时,可以通过内网访问minio控制台:
貌似很遗憾,页面可以正常访问,但是在登录之后报错:
1[zhangcong@master ~]$ kubectl port-forward --address 0.0.0.0 -n minio-dev service/minio-service 9090:5000
2Forwarding from 0.0.0.0:9090 -> 5000
3Handling connection for 9090
4
5Handling connection for 9090
6E0102 00:51:59.936118 34019 portforward.go:381] error copying from remote stream to local connection: readfrom tcp4 192.168.0.91:9090->192.168.0.115:53876: write tcp4 192.168.0.91:9090->192.168.0.115:53876: write: broken pipe
7
8Handling connection for 9090
9E0102 00:52:37.517767 34019 portforward.go:347] error creating error stream for port 9090 -> 5000: Timeout occurred
10E0102 00:53:00.249379 34019 portforward.go:347] error creating error stream for port 9090 -> 5000: Timeout occurred
这错误与 minikube 无关。
在 https://github.com/minio/console/issues/2539 上找到有一个变通的方法:
终端运行:
浏览器打开
只要终端出现 Timeout occurred 或 broken pipe 时,立刻按下 CTRL + C ,以便将重新启动端口转发
在web用户界面中重新登录,直到完全验证并加载
一旦登录验证完成,端口转发的错误就不存在了
评论