K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)

K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)

  • 一、下载容器镜像
  • 二、快速测试
    • 1、启动容器
    • 2、查看日志
    • 3、浏览器访问
    • 4、退出并删除容器
  • 三、准备Yaml文件
    • 1、命名空间 owncloud-ns.yaml
    • 2、部署 owncloud-deployment.yaml
    • 3、服务 owncloud-svc.yaml
  • 四、部署
    • 1、创建Secret,拉取容器镜像需要
    • 2、部署
  • 五、问题
    • 1、拉取容器镜像失败
    • 2、第二次安装或者重建容器时失败
  • 六、参考
  • 附专栏链接

一、下载容器镜像

[root@harbor ~]# docker pull owncloud/server:10.6
[root@harbor ~]# docker tag owncloud/server:10.6 harbor.demo/owncloud/server:10.6
[root@harbor ~]# docker push harbor.demo/owncloud/server:10.6
  • harbor.demo 是部署在集群外的容器镜像仓库
  • 查找更多owncloud容器镜像 https://hub.docker.com/r/owncloud/server/

二、快速测试

1、启动容器

[root@harbor ~]# docker run -d --name aOwncloud -p8080:8080 harbor.demo/owncloud/server:10.6

2、查看日志

[root@harbor ~]# docker logs --follow aOwncloud
Creating volume folders...
Creating hook folders...
Removing custom folder...
Linking custom folder...
Removing config folder...
Linking config folder...
Writing config file...
Fixing base perms...
Fixing data perms...
Fixing hook perms...
Installing server database...
creating sqlite db
ownCloud was successfully installed
ownCloud is already latest version
Writing objectstore config...
Writing php config...
Updating htaccess config...
.htaccess has been updated
Writing apache config...
Enabling cron background...
Set mode for background jobs to 'cron'
Touching cron configs...
Starting cron daemon...
Starting apache daemon...

3、浏览器访问

  • 地址:http://harbor.demo:8080
    K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)_第1张图片
  • 登录owncloud,用户名 admin 密码 admin
    K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)_第2张图片

4、退出并删除容器

[root@harbor ~]# docker stop aOwncloud
[root@harbor ~]# docker rm aOwncloud

三、准备Yaml文件

1、命名空间 owncloud-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: owncloud

2、部署 owncloud-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: owncloud-server
  namespace: owncloud
spec:
  replicas: 1
  selector:
    matchLabels:
      app: owncloud
  template:
    metadata:
      labels:
        app: owncloud  
    spec:
      imagePullSecrets:
      - name: harbor.demo
      containers:
      - name: owncloud-server
        image: harbor.demo/owncloud/server:10.6
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: http
        env:
        - name: OWNCLOUD_VERSION
          value: "10.6"
        - name: OWNCLOUD_DB_TYPE
          value: mysql
        - name: OWNCLOUD_DB_NAME
          value: owncloud
        - name: OWNCLOUD_DB_USERNAME
          value: owncloud
        - name: OWNCLOUD_DB_PASSWORD
          value: owncloud
        - name: OWNCLOUD_DB_HOST
          value: 172.16.0.89
        - name: OWNCLOUD_DB_PORT
          value: "3306"
        - name: OWNCLOUD_MYSQL_UTF8MB4
          value: "true"
        - name: OWNCLOUD_REDIS_ENABLED
          value: "true"
        - name: OWNCLOUD_REDIS_HOST
          value: 172.16.0.89
        - name: OWNCLOUD_REDIS_DB
          value: "3"
        - name: OWNCLOUD_REDIS_PASSWORD
          value: "123456"
        - name: REDIS_PASSWORD
          value: "1234567"
        - name: OWNCLOUD_REDIS_PORT
          value: "6379"
        - name: ADMIN_USERNAME
          value: admin
        - name: ADMIN_PASSWORD
          value: admin
        - name: HTTP_PORT
          value: "80"
        - name: OWNCLOUD_DOMAIN
          value: 0.0.0.0
        resources:
          limits:
            memory: 512Mi
          requests:
            cpu: 500m
            memory: 300Mi
  • imagePullSecrets 拉取奖项需要的用户名和密码信息,保存在Secret中,下面会创建
  • 数据库使用MySQL,在搭建集群之前就在WIN10上安装了MySQL5.7,所以一直用
  • Redis也是用WIN10上的,如果Redis设置了密码,则配置参数OWNCLOUD_REDIS_PASSWORD
  • Redis数据库OWNCLOUD_REDIS_DB这里用的是 “3”,不带引号会报错
  • 更多环境变量参数参考 https://github.com/owncloud-docker/base#available-environment-variables

3、服务 owncloud-svc.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: owncloud
    version: v10.6
  name: owncloud
  namespace: owncloud
spec:
  ports:
  - nodePort: 30080
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: owncloud
  type: NodePort

四、部署

1、创建Secret,拉取容器镜像需要

[root@master1 owncloud]# kubectl create secret docker-registry harbor.demo --docker-server=harbor.demo --docker-username=admin --docker-password=Harbor12345  --namespace=owncloud
  • 下面的参数可以根据实际情况修改
    – Secret名称harbor.demo
    – 服务器:harbor.demo
    – 用户名:admin
    – 密码:Harbor12345
    – 命名空间 owncloud

2、部署

[root@master1 owncloud]# kubectl apply -f owncloud-ns.yaml
[root@master1 owncloud]# kubectl apply -f owncloud-deployment.yaml
[root@master1 owncloud]# kubectl apply -f owncloud-svc.yaml
  • 简单的执行,指定目录,例如 kubectl apply -f /opt/install/owncloud

五、问题

1、拉取容器镜像失败

  • 错误日志
[root@master1 yaml]# kubectl describe pod/owncloud-server-8b85cf4f9-wrp9c -n owncloud
... ...
Failed to pull image "harbor.demo/owncloud/server:10.6": rpc error: code = Unknown desc = Error response from daemon: pull access denied for harbor.demo/owncloud/server, repository does not exist or may require 'docker login'
Error: ErrImagePull
Back-off pulling image "harbor.demo/owncloud/server:10.6"
Error: ImagePullBackOff
  • 从私有仓库拉取容器镜像需要鉴权,检查secret是否正确,其中的信息是Base64编码,可以解码检查信息是否正确
[root@master1 owncloud]# kubectl get secret harbor.demo -o yaml 
[root@master1 owncloud]# kubectl get secrets harbor.demo --output="jsonpath={.data.\.dockerconfigjson}" | base64 -d

2、第二次安装或者重建容器时失败

  • 正确启动日志

Creating volume folders…
Creating hook folders…
Waiting for MySQL…
services are ready!
Waiting for Redis…
services are ready!
Removing custom folder…
Linking custom folder…
Removing config folder…
Linking config folder…
Writing config file…
Fixing base perms…
Fixing data perms…
Fixing hook perms…
Installing server database…
ownCloud was successfully installed
ownCloud is already latest version
Writing objectstore config…
Writing php config…
Updating htaccess config…
.htaccess has been updated
Writing apache config…
Enabling cron background…
Set mode for background jobs to ‘cron’
Touching cron configs…
Starting cron daemon…
Starting apache daemon…

  • 错误日志

Installing server database…
The username is already being used

  • 原因:在重建容器时触发初始化
    – 参考 https://github.com/owncloud-docker/server/issues/104
    – 参考 https://central.owncloud.org/t/upgrade-to-the-username-is-already-being-used/17162/7
  • 解决方法,每次安装或者重启的时候,环境变量ADMIN_USERNAME随便写个值,使用admin账户登录后,删除该新建账户

六、参考

  • https://github.com/owncloud-docker/server
  • https://my.oschina.net/u/2306127/blog/2239802
  • https://owncloud.com/news/running-owncloud-in-kubernetes-with-rook-ceph-storage-step-by-step/
  • https://blog.csdn.net/weixin_34315485/article/details/92211317
  • https://github.com/owncloud-docker/server/issues/104
  • https://central.owncloud.org/t/upgrade-to-the-username-is-already-being-used/17162/9

附专栏链接

K8S-Demo集群实践00:搭建镜像仓库Harbor+安全扫描
K8S-Demo集群实践01:准备VMware虚拟机模板
K8S-Demo集群实践02:准备VMware虚拟机3台Master+3台Node
K8S-Demo集群实践03:准备集群各组件间HTTPS通讯需要的x509证书
K8S-Demo集群实践04:部署etcd三节点高可用集群
K8S-Demo集群实践05:安装kubectl并配置集群管理员账户
K8S-Demo集群实践06:部署kube-apiserver到master节点(3个无状态实例)
K8S-Demo集群实践07:kube-apiserver高可用方案
K8S-Demo集群实践08:部署高可用kube-controller-manager集群
K8S-Demo集群实践09:部署高可用kube-scheduler集群
K8S-Demo集群实践10:部署ipvs模式的kube-proxy组件
K8S-Demo集群实践11:部署ipvs模式的kube-kubelet组件
K8S-Demo集群实践12:部署Calico网络
K8S-Demo集群实践13:部署集群CoreDNS
K8S-Demo集群实践14:部署集群监控服务Metrics Server
K8S-Demo集群实践15:部署Kubernetes Dashboard
K8S-Demo集群实践16:部署Kube-Prometheus
K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)
K8S-Demo集群实践18:构建宇宙中第一个基础容器镜像


  • 先用起来,通过操作实践认识k8s,积累多了自然就理解了
  • 把理解的知识分享出来,自造福田,自得福缘
  • 追求简单,容易使人理解
  • 知识的上下文也是知识的一部分,例如版本,时间等
  • [email protected] 2021-1-16。

你可能感兴趣的:(k8s-demo,kubernetes,k8s,docker)