Skip to content

Latest commit

 

History

History
95 lines (74 loc) · 2.87 KB

File metadata and controls

95 lines (74 loc) · 2.87 KB

Backup and Restore Methods

In this section, we will take a look at backup and restore methods

Backup Candidates

bc

Resource Configuration

  • Imperative way

    rci

  • Declarative Way (Preferred approach)

    apiVersion: v1
    kind: Pod
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
      - name: nginx-container
        image: nginx
    

rcd

  • A good practice is to store resource configurations on source code repositories like github.

    rcd1

Backup - Resource Configs

  • A better approach to backing up resource configuration is to use query the kube-apiserver using 'kubectl' or by accessing the API server directly and save all resource configurations for all objects created on the cluster has a copy.

    $ kubectl get all --all-namespaces -o yaml > all-deploy-services.yaml (only for few resource groups)
    
  • There are many other resource groups that must be considered. There are tools like ARK or now called Velero by Heptio that can do this for you.

    brc

Backup - ETCD

  • The ETCD cluster stores information about the state of our cluster. So information about the cluster itself, the nodes and every other resources as created within the cluster are store here.

  • So, instead of backing up resources as before, you may choose to backup the ETCD cluster itself.

  • While configuring ETC, we have configured where all the data would be stored in the data directory (/var/lib/etcd)

    be

  • You can take a snapshot of the etcd database by using etcdctl utility snapshot save command.

    $ ETCDCTL_API=3 etcdctl snapshot save snapshot.db
    
    $  ETCDCTL_API=3 etcdctl snapshot status snapshot.db
    

    be1

Restore - ETCD

  • To restore etcd from the backup at later in time. First stop kube-apiserver service

    $ service kube-apiserver stop
    
  • Run the etcdctl snapshot restore command

  • Update the etcd service

  • Reload system configs

    $ systemctl daemon-reload
    
  • Restart etcd

    $ service etcd restart
    

    er

  • Start the kube-apiserver

    $ service kube-apiserver start
    

With all etcdctl commands specify the cert,key,cacert and endpoint for authentication.

$ ETCDCTL_API=3 etcdctl --endpoints=https://[127.0.0.1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/etcd-server.crt \
  --key=/etc/kubernetes/pki/etcd/etcd-server.key snapshot save /tmp/snapshot.db

erest

K8s Reference Docs