k8s中部署rsyncd

私有化部署中,有一个比较耗时的操作是地图数据的上传。每次都需要手动将地图数据拷贝到k8s的PVC中。为了解决这个问题,通过pod部署一个rsyncd守护进程,并通过NodePort类型Service将服务暴露出来以方便同事上传。

镜像来源"https://hub.docker.com/r/servercontainers/rsync"。

创建配置文件和凭据文件,

配置文件rsyncd.conf:

复制代码
    use chroot = false
    strict modes = false
    hosts allow = *
    log file = /data/rsyncd.log
    auth users = rsyncuser
    secrets file = /etc/rsyncd.secrets

    [map]
    path = /data/map
    read only = false
    transfer logging = yes
    hosts allow = *
    uid = 0   #实际使用按照要求修改
    gid = 0   #实际使用按照要求修改

凭据文件rsyncd.secrets:

复制代码
rsyncuser:longlongpassword

命令行方式创建configmap,

复制代码
kubectl create configmap cmrsyncd --from-file=rsyncd.secrets --from-file=rsyncd.conf

rsyncd的yaml文件,

复制代码
apiVersion: v1
kind: Service
metadata:
    name: rsyncd
spec:
    type: NodePort
    ports:
    - name: rsyncd
      port: 873
      targetPort: 873
      protocol: TCP
      nodePort: 30010
    selector:
      app: rsyncd
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rsyncd
  labels:
    app: rsyncd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rsyncd
  template:
    metadata:
      labels:
        app: rsyncd
    spec:
      containers:
        - name: rsyncd
          image: servercontainers/rsync:latest
          ports:
            - containerPort: 873
          volumeMounts:
            - name: data-volume
              mountPath: /data
            - name: cmrsyncd
              mountPath: /etc/rsyncd.conf
              subPath: rsyncd.conf
              readOnly: true
            - name: cmrsyncd
              mountPath: /etc/rsyncd.secrets
              subPath: rsyncd.secrets
              readOnly: true
          resources:
           limits:
             cpu: 200m
             memory: 512Mi
           requests:
             cpu: 100m
             memory: 128Mi  
      volumes:
        - name: cmrsyncd
          configMap:
            name: cmrsyncd 
        - name: data-volume
          persistentVolumeClaim:
            claimName: data-pvc

上传命令如下,

复制代码
# 上传文件map.data
rsync -avz map.data  rsyncuser@192.168.1.1::map  --port 30010

如果不想每次手动输入密码,可以将密码写入文件rsync.pass中,并将文件权限改为"600"

复制代码
# 修改文件权限
chmod 600 rsync.pass

# 上传文件map.data
rsync -avz map.data  rsyncuser@192.168.1.1::map --password-file=./rsync.pass --port 30010

这样文件就会上传到容器目录"/data/map"中,也即上传到PVC中。

相关推荐
小p6 小时前
docker学习: 2. 构建镜像Dockerfile
docker
小p1 天前
docker学习: 1. docker基本使用
docker
蝎子莱莱爱打怪1 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀1 天前
Docker部署Nacos
docker·容器
缓解AI焦虑1 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
1candobetter2 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka
シ風箏2 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
BugShare2 天前
继《小爱音响》详细说下怎么部署,尤其是关于Docker部分
docker·nas·xiaomusic
阿里云云原生2 天前
Kubernetes 官方再出公告,强调立即迁移 Ingress NGINX
kubernetes
至此流年莫相忘2 天前
Kubernetes实战篇之配置与存储
云原生·容器·kubernetes