k8s部署单机模式的minio和minio-client
项目使用minio,准备在k8s环境部署一套minio试用。命令参数来固定控制台端口,否则页面会无法访问。yaml中使用的svc是。nodePort类型。,可以看到以上控制台。出现以上页面表示成功。
k8s部署单机模式的minio和minio-client
一、k8s部署minio
1.1说明
项目使用minio,准备在k8s环境部署一套minio试用。
1.关于minio的原理和概念参考:
https://mp.weixin.qq.com/s?__biz=MzI3MDM5NjgwNg==&mid=2247487162&idx=1&sn=39c683a43ec2678fbf6d767f6ab6dcc6&chksm=ead0f253dda77b459edaf514cf72fc03546f2c5075c7b131c34b34772ca3517cab170d94c056#rd
2. 官网k8s部署minio方法说明:
https://min.io/docs/minio/kubernetes/upstream/index.html
1.2 yaml内容
参考:
https://www.jianshu.com/p/2d45990dd652
https://raw.githubusercontent.com/minio/docs/master/source/extra/examples/minio-dev.yaml文档yaml内容:
# Deploys a new Namespace for the MinIO Pod
apiVersion: v1
kind: Namespace
metadata:
name: minio-dev # Change this value if you want a different namespace name
labels:
name: minio-dev # Change this value to match metadata.name
---
# Deploys a new MinIO Pod into the metadata.namespace Kubernetes namespace
#
# The `spec.containers[0].args` contains the command run on the pod
# The `/data` directory corresponds to the `spec.containers[0].volumeMounts[0].mountPath`
# That mount path corresponds to a Kubernetes HostPath which binds `/data` to a local drive or volume on the worker node where the pod runs
#
apiVersion: v1
kind: Pod
metadata:
labels:
app: minio
name: minio
namespace: minio-dev # Change this value to match the namespace metadata.name
spec:
containers:
- name: minio
image: quay.io/minio/minio:latest
command:
- /bin/bash
- -c
args:
- minio server /data --console-address :9090
volumeMounts:
- mountPath: /data
name: localvolume # Corresponds to the `spec.volumes` Persistent Volume
nodeSelector:
kubernetes.io/hostname: kubealpha.local # Specify a node label associated to the Worker Node on which you want to deploy the pod.
volumes:
- name: localvolume
hostPath: # MinIO generally recommends using locally-attached volumes
path: /mnt/disk1/data # Specify a path to a local drive or volume on the Kubernetes worker node
type: DirectoryOrCreate # The path to the last directory must exist
实际使用到的minio.yaml配置文件:
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
app: minio
release: minio
name: minio
namespace: sscs-dev
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
volumeMode: Filesystem
hostPath:
path: /home/cicd/sscs-dev/minio
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
# This name uniquely identifies the PVC. Will be used in deployment below.
name: minio-pv-claim
labels:
app: minio-storage-claim
namespace: sscs-dev
spec:
# Read more about access modes here: https://kubernetes.io/docs/user-guide/persistent-volumes/#access-modes
accessModes:
- ReadWriteOnce
resources:
# This is the request for storage. Should be available in the cluster.
requests:
storage: 10Gi
# Uncomment and add storageClass specific to your requirements below. Read more https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1
#storageClassName:
---
apiVersion: apps/v1
kind: Deployment
metadata:
# This name uniquely identifies the Deployment
name: minio-deployment
namespace: sscs-dev
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: minio
template:
metadata:
labels:
# Label is used as selector in the service.
app: minio
spec:
# Refer to the PVC created earlier
volumes:
- name: storage
persistentVolumeClaim:
# Name of the PVC created earlier
claimName: minio-pv-claim
imagePullSecrets:
- name: sscs-secret
containers:
- name: minio
# Pulls the default MinIO image from Docker Hub
image: artifact.srdcloud.cn/khala_insight-release-docker-local/minio:latest
# 注意:--console-address ":5000"用来固定控制台访问端口,否则页面会无法访问控制台
command:
- /bin/sh
- -c
- minio server /data --console-address ":5000"
args:
- server
- /storage
env:
# MinIO access key and secret key
- name: MINIO_ACCESS_KEY
value: "admin123"
- name: MINIO_SECRET_KEY
value: "admin123"
ports:
- name: data
containerPort: 9000
protocol: "TCP"
- name: console
containerPort: 5000
protocol: "TCP"
# Mount the volume into the pod
volumeMounts:
- name: storage # must match the volume name, above
mountPath: "/storage"
---
apiVersion: v1
kind: Service
metadata:
namespace: sscs-dev
name: minio-service
spec:
type: NodePort
ports:
- name: data
port: 9000
targetPort: 9000
protocol: TCP
nodePort: 31955
- name: console
port: 5000
targetPort: 5000
protocol: TCP
nodePort: 32108
selector:
app: minio
注意事项:
要添加--console-address ":5000"
命令参数来固定控制台端口,否则页面会无法访问。
1.3 步骤
1.3.1 创建资源
执行命令:kubectl apply -f minio.yaml
1.3.2 查看启动日志
kubectl get pod -n sscs-dev | grep minio
查看pod运行状态,正常:
kubectl logs -f minio-deployment-54648b586-kxcbn -n sscs-dev
查看pod运行日志:
根据日志可获取以下信息:
api端口
为9000
,控制台端口
为5000
控制台端口
为5000
,说明命令参数--console-address ":5000"
生效。
1.3.3 查看svc并访问控制台
执行命令:kubectl get svc -n sscs-dev | grep minio
yaml中使用的svc是nodePort类型
,可以看到以上控制台5000端口
映射主机32108端口
,则访问地址为: 服务器ip:32108
:
出现以上页面表示成功
二、docker部署minio-client
参考文章:
https://blog.csdn.net/weixin_45821811/article/details/119116172
2.1 查找镜像
执行命令docker search minio/mc
2.2 运行镜像
执行命令: docker run -it --entrypoint=/bin/sh minio/mc
参数说明:
-i: 以交互模式运行容器,通常与 -t 同时使用;
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
注意:
启动容器时要加上参数:-it --entrypoint=/bin/sh
,启动后自动进入容器终端,否则容器一启动就会退出。
2.3 绑定minio server
- 执行完容器启动命令:
docker run -it --entrypoint=/bin/sh minio/mc
之后,会自动进入容器终端。 - 此时在容器内部执行命令绑定minio server:
mc config host add minio http://132.1xx.xx.5:31955
说明:
mc config host add minio http://132.1xx.xx.5:31955
minio 为别名,可自定义
http://132.1xx.xx.5:31955 为minio服务部署的ip和api映射的主机端口,1.3.3 中可查看api端口9000映射的主机端口
- 命令行会要求输入
access key
和secret key
(参考minio.yaml中配置的值)
至此minio-client部署完成,可以使用相关命令来直接操作minio server
更多推荐
所有评论(0)