当前位置: 首页 > 软件库 > 云计算 > 云原生 >

kube-backup

💾 Kubernetes resource state sync to git
授权协议 MIT License
开发语言 Google Go
所属分类 云计算、 云原生
软件类型 开源软件
地区 不详
投 递 者 鲁波光
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

kube-backup

Quick 'n dirty kubernetes state backup script, designed to be ran as kubernetes Job. Think of it like RANCID for kubernetes.

Props to @gianrubio for coming up with the idea.

Setup

Use the deployment example (ssh or AWS CodeCommit authentication) and deploy a kubernetes CronJob primitive in your kubernetes (1.5 and up) cluster ensuring backups of kubernetes resource definitions to your private git repo.

Define the following environment parameters:

  • GIT_REPO - GIT repo url. Required
  • GIT_PREFIX_PATH - Path to the subdirectory in your repository. Default: .
  • NAMESPACES - List of namespaces to export. Default: all
  • GLOBALRESOURCES - List of global resource types to export. Default: namespace
  • RESOURCETYPES - List of resource types to export. Default: ingress deployment configmap svc rc ds networkpolicy statefulset storageclass cronjob. Notice that Secret objects are intentionally not exported by default (see git-crypt section for details).
  • GIT_USERNAME - Display name of git user. Default: kube-backup
  • GIT_EMAIL - Email address of git user. Default: kube-backup@example.com
  • GIT_BRANCH - Use a specific git branch . Default: master
  • GITCRYPT_ENABLE - Use git-crypt for data encryption. See git-crypt section for details. Default: false
  • GITCRYPT_PRIVATE_KEY - Path to private gpg key for git-crypt. See git-crypt section for details. Default: /secrets/gpg-private.key
  • GITCRYPT_SYMMETRIC_KEY - Path to shared symmetric key for git-crypt. See git-crypt section. Default: /secrets/symmetric.key

Choose one of two authentication mechanisms:

  • When using AWS CodeCommit and policy-based access from AWS, modify your cluster configuration to provide GitPull and GitPush access for that CodeCommit repo to your cluster. If using kops, the configuration will look something like this:
additionalPolicies:
    node: |
      [
        {
          "Effect": "Allow",
          "Action": [
            "codecommit:GitPull",
            "codecommit:GitPush"
          ],
          "Resource": "arn:aws:codecommit:<region>:<account name>:<repo-name>"
        }
      ]

NOTE: in this deployment, the ssh volume and secret are not present.

  • When using a different repository (GitHub, BitBucket, etc.), mount a configured ssh directory in /backup/.ssh with the following files:

    • known_hosts - Preloaded with SSH host key of $GIT_REPO host.
    • id_rsa - SSH private key of user allowed to push to $GIT_REPO.

Easiest way of doing this is:

ssh-keygen -f ./id_rsa
ssh-keyscan $YOUR_GIT_HOST > known_hosts

kubectl create secret generic kube-backup-ssh -n kube-system --from-file=id_rsa --from-file=known_hosts

NOTE: If id_rsa isn't found in your ssh directory, the backup script will assume you're using AWS CodeCommit.

Optional:

  • Modify the snapshot frequency in spec.schedule using the cron format.
  • Modify the number of successful and failed finished jobs to retain in spec.successfulJobsHistoryLimit and spec.failedJobsHistoryLimit.
  • If using RBAC (1.6+), use the ClusterRole and ClusterRoleBindings in rbac.yaml.

git-crypt

For security reasons Secret objects are not exported by default. However there is a possibility to store them safely using the git-crypt project.

Prerequisites

Your repository has to be already initialized with git-crypt. Minimal configuration is listed below. For details and full information see using git-crypt.

cd repo
git-crypt init
cat <<EOF > .gitattributes
*.secret.yaml filter=git-crypt diff=git-crypt
.gitattributes !filter !diff
EOF
git-crypt add-gpg-user <USER_ID>
git add -A
git commit -a -m "initialize git-crypt"

Optional:

  • You may choose any subdirectory for storing .gitattributes file (useful when using GIT_PREFIX_PATH).
  • You may encrypt additional files other than secret.yaml. Add additional lines before the .gitattribute filter. You may also use wildcard * to encrypt all files within the directory.

Enable git-crypt

To enable encryption feature:

  • Set pod environment variable GITCRYPT_ENABLE to true

    spec:
      containers:
      - env:
        - name: GITCRYPT_ENABLE
          value: "true"
    
  • Create additional Secret object containing either gpg-private or symmetric key

    apiVersion: v1
    kind: Secret
    metadata:
      name: kube-backup-gpg
      namespace: kube-system
    data:
      gpg-private.key: <base64_encoded_key>
      symmetric.key: <base64_encoded_key>
    
  • Mount keys from Secret as additional volume

    spec:
      containers:
      - volumeMounts:
        - mountPath: /secrets
          name: gpgkey
      volumes:
      - name: gpgkey
        secret:
          defaultMode: 420
          secretName: kube-backup-gpg
    
  • Add secret object name to RESOURCETYPES variable

    spec:
      containers:
      - env:
        - name: RESOURCETYPES
          value: "ingress deployment configmap secret svc rc ds thirdpartyresource networkpolicy statefulset storageclass cronjob"
    
  • If using RBAC (1.6+), add secrets to resources

    rules:
    - apiGroups: ["*"]
      resources: [
        "configmaps",
        "secrets",
    
  • (Optional): $GITCRYPT_PRIVATE_KEY and $GITCRYPT_SYMMETRIC_KEY variables are the combination of path where Secret volume is mounted and the name of item key from that object. If you change any value of them from the above example you may need to set this variables accordingly.

Result

All configured resources will be exported into a directory tree structure in YAML format following a $namespace/$name.$type.yaml file structure.

.
├── kube-system
│   ├── attachdetach-controller.serviceaccounts.yaml
│   ├── canal-config.configmap.yaml
│   ├── canal.daemonset.yaml
│   ├── canal.serviceaccounts.yaml
│   ├── certificate-controller.serviceaccounts.yaml
│   ├── cronjob-controller.serviceaccounts.yaml
│   ├── daemon-set-controller.serviceaccounts.yaml
│   ├── default.serviceaccounts.yaml
│   ├── deployment-controller.serviceaccounts.yaml
│   ├── disruption-controller.serviceaccounts.yaml
│   ├── dns-controller.deployment.yaml
│   ├── dns-controller.serviceaccounts.yaml
│   ├── endpoint-controller.serviceaccounts.yaml
│   ├── generic-garbage-collector.serviceaccounts.yaml
│   ├── horizontal-pod-autoscaler.serviceaccounts.yaml
│   ├── job-controller.serviceaccounts.yaml
│   ├── kube-backup-gpg.secret.yaml
│   ├── kube-backup.serviceaccounts.yaml
│   ├── kube-backup-ssh.secret.yaml
│   ├── kube-dns-autoscaler.configmap.yaml
│   ├── kube-dns-autoscaler.deployment.yaml
│   ├── kube-dns-autoscaler.serviceaccounts.yaml
│   ├── kube-dns.deployment.yaml
│   ├── kube-dns.serviceaccounts.yaml
│   ├── kube-dns.service.yaml
│   ├── kubelet.service.yaml
│   ├── kube-prometheus-exporter-kube-controller-manager.service.yaml
│   ├── kube-prometheus-exporter-kube-dns.service.yaml
│   ├── kube-prometheus-exporter-kube-etcd.service.yaml
│   ├── kube-prometheus-exporter-kube-scheduler.service.yaml
│   ├── kube-proxy.serviceaccounts.yaml
│   ├── kube-state-backup-new.cronjob.yaml
│   ├── kube-sysctl.daemonset.yaml
│   ├── letsencrypt-prod.secret.yaml
│   ├── namespace-controller.serviceaccounts.yaml
│   ├── node-controller.serviceaccounts.yaml
│   ├── openvpn-ccd.configmap.yaml
│   ├── openvpn-crl.configmap.yaml
│   ├── openvpn.deployment.yaml
│   ├── openvpn-ingress.service.yaml
│   ├── openvpn-pki.secret.yaml
│   ├── openvpn-portmapping.configmap.yaml
│   ├── openvpn-settings.configmap.yaml
│   ├── persistent-volume-binder.serviceaccounts.yaml
│   ├── pod-garbage-collector.serviceaccounts.yaml
│   ├── replicaset-controller.serviceaccounts.yaml
│   ├── replication-controller.serviceaccounts.yaml
│   ├── resourcequota-controller.serviceaccounts.yaml
│   ├── route53-config.secret.yaml
│   ├── service-account-controller.serviceaccounts.yaml
│   ├── service-controller.serviceaccounts.yaml
│   ├── statefulset-controller.serviceaccounts.yaml
│   ├── sysctl-options.configmap.yaml
│   ├── tiller-deploy.deployment.yaml
│   ├── tiller-deploy.service.yaml
│   ├── tiller.serviceaccounts.yaml
│   └── ttl-controller.serviceaccounts.yaml
├── prd
│   ├── initdb.configmap.yaml
│   ├── example-app.deployment.yaml
│   ├── example-app.ingress.yaml
│   ├── example-app.secret.yaml
│   ├── example-app.service.yaml
│   ├── postgres-admin.secret.yaml
│   ├── postgresql.deployment.yaml
│   ├── postgresql.service.yaml
│   ├── postgres.secret.yaml
│   ├── prd.example.com.secret.yaml
│   ├── redis.service.yaml
│   └── redis-standalone.rc.yaml
└── staging
    ├── initdb.configmap.yaml
    ├── example-app.deployment.yaml
    ├── example-app.ingress.yaml
    ├── example-app.secret.yaml
    ├── example-app.service.yaml
    ├── postgres-admin.secret.yaml
    ├── postgresql.deployment.yaml
    ├── postgresql.service.yaml
    ├── postgres.secret.yaml
    ├── staging.example.com.secret.yaml
    ├── redis.service.yaml
    └── redis-standalone.rc.yaml

3 directories, 80 files

This project is MIT licensed.

  • 一、kube-apiserver组件部署 获取最新更新以及文章用到的软件包,请移步点击:查看更新 1、下载安装包 #下载安装包 mkdir -p /opt/kubernetes/{bin,cfg,ssl,logs} wget https://dl.k8s.io/v1.20.1/kubernetes-server-linux-amd64.tar.gz #解压 tar -xf kubernetes

  • kube-keepalived-vip Kubernetes Virtual IP address/es using keepalived AKA "how to set up virtual IP addresses in kubernetes using IPVS - The Linux Virtual Server Project". Overview kubernetes v1.6 off

  • suse 12 二进制部署 Kubernetes 集群系列合集: suse 12 二进制部署 Kubernetets 1.19.7 - 第00章 - 环境准备 suse 12 二进制部署 Kubernetets 1.19.7 - 第01章 - 创建CA证书和kubectl集群管理命令 suse 12 二进制部署 Kubernetets 1.19.7 - 第02章 - 部署etcd集群 suse 1

  • 参考文档: https://github.com/opsnull/follow-me-install-kubernetes-cluster 感谢作者的无私分享。 集群环境已搭建成功跑起来。 文章是部署过程中遇到的错误和详细操作步骤记录。如有需要对比参考,请按照顺序阅读和测试。 kubernetes master 节点运行如下组件: kube-apiserver kube-scheduler kub

  • 也可以用nginx、keepalived做负载均衡,看大家的需求。 # yum -y install haproxy keepalived haproxy的配置文件(三台一样): cat > /etc/haproxy/haproxy.cfg <<EOF global log /dev/log local0 log /dev/log local1 notice c

  • 阿里云的slb有回环的问题,因此采用阿里云HaVip+keepalived+Haproxy实现kube-apiserver的高可用。 由于HaVip只能绑定两个后端,且为节省机器,将Haproxy复用到master01、02节点。 Master01、02节点通过yum安装HAProxy和KeepAlived yum install keepalived haproxy -y 配置HAProxy(

  • kube-apiserver 准备 1、kube-apiserver 服务器配置 对外ip 内网ip cpu 内存 硬盘 192.168.3.10 172.172.1.1 64 256 1T 192.168.3.11 172.172.1.2 64 256 1T 192.168.3.12 172.172.1.3 64 256 1T 192.168.3.13 172.172.1.4 64 256 1T

 相关资料
  • Backup This project is welcoming new contributors and maintainers. See CONTRIBUTING.md Backup is a system utility for Linux and Mac OS X, distributed as a RubyGem, that allows you to easily perform ba

  • Kube 足够的简单,足够小,具有很强的自适应能力,是个响应式的 CSS 框架。它拥有最新最炫的网格和漂亮的字体排版,没有任何样式绑定,给用户以绝对的自由。 支持的浏览器包括: Latest Chrome Latest Firefox Latest Safari Latest Opera IE 8+ 手机浏览器

  • Areca Backup 是一个用Java编写的个人文件备份工具,支持压缩、打包、加密等操作。

  • Borg 是一个支持去重和压缩的备份程序,同时也支持认证加密。其主要目的是提供一个高校而且安全的方法用于数据备份。数据的去重技术用于每日增量备份。 使用方法: $ borg init /mnt/backup$ borg create /mnt/backup::Monday ~/Documents$ borg create --stats /mnt/backup::Tuesday ~/Documen

  • backup-utils 是 Github 企业备份工具,它包括一些备份和恢复工具。这些备份工具实现了多项用于备份主机的高级功能,还原功能也已经包括在 GitHub Enterprise 中。 特性: 通过两个简单的实用工具来完善GitHub Enterprise Server备份和恢复系统: ghe-backup和ghe-restore。 联机备份。在备份运行期间,无需将GitHub设备置于维护

  • Kiwi Backup 是一个在线备份系统(非开源),可以通过ADSL网络处理超过200G的数据,通过块提升和无重复的数据算法来降低网络带宽需求,可以通过SSL传输层进行数据传输。