-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Pre/Post hooks example. #795
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2018 the Heptio Ark contributors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM alpine:3.7 | ||
|
||
MAINTAINER Wayne Witzel III <[email protected]> | ||
|
||
RUN apk add --no-cache ca-certificates | ||
RUN apk add --update --no-cache busybox util-linux | ||
|
||
ENTRYPOINT ["/bin/sh", "-c", "sleep infinity"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,6 @@ As of version v0.7.0, Ark also supports "post" hooks - these execute after all c | |
completed, as well as after all the additional items specified by custom actions have been backed | ||
up. | ||
|
||
An example of when you might use both pre and post hooks is freezing a file system. If you want to | ||
ensure that all pending disk I/O operations have completed prior to taking a snapshot, you could use | ||
a pre hook to run `fsfreeze --freeze`. Next, Ark would take a snapshot of the disk. Finally, you | ||
could use a post hook to run `fsfreeze --unfreeze`. | ||
|
||
There are two ways to specify hooks: annotations on the pod itself, and in the Backup spec. | ||
|
||
### Specifying Hooks As Pod Annotations | ||
|
@@ -51,4 +46,49 @@ Ark v0.7.0+ continues to support the original (deprecated) way to specify pre ho | |
Please see the documentation on the [Backup API Type][1] for how to specify hooks in the Backup | ||
spec. | ||
|
||
## Hook Example with fsfreeze | ||
|
||
We are going to walk through using both pre and post hooks for freezing a file system. Freezing the | ||
file system is useful to ensure that all pending disk I/O operations have completed prior to taking a snapshot. | ||
|
||
We will be using [example/nginx-app/with-pv.yaml][2] for this example. Follow the [steps for your provider][3] to | ||
setup this example. | ||
|
||
### Annotations | ||
|
||
The Ark [example/nginx-app/with-pv.yaml][2] serves as an example of adding the pre and post hook annotations directly | ||
to your declarative deployment. Below is an example of what updating an object in place might look like. | ||
|
||
Place Ark in restore only mode. This will prevent Ark backups from running while you are adding the | ||
annotations and avoid the condition where the pre hook freezes the file system, but there is no | ||
post hook setup to unfreeze it. | ||
|
||
```shell | ||
kubectl patch -n heptio-ark config default --type merge -p '{"restoreOnlyMode": true}' | ||
``` | ||
|
||
Now you patch your pod with the required annotations. | ||
|
||
```shell | ||
kubectl annotate pod -n nginx-example -l app=nginx pre.hook.backup.ark.heptio.com/command='["/sbin/fsfreeze", "--freeze", "/var/log/nginx"]' | ||
kubectl annotate pod -n nginx-example -l app=nginx pre.hook.backup.ark.heptio.com/containr=fsfreeze | ||
|
||
kubectl annotate pod -n nginx-example -l app=nginx post.hook.backup.ark.heptio.com/command='["/sbin/fsfreeze", "--unfreeze", "/var/log/nginx"]' | ||
kubectl annotate pod -n nginx-example -l app=nginx post.hook.backup.ark.heptio.com/containr=fsfreeze | ||
``` | ||
|
||
Finally, remove Ark from restore only mode and test the pre and post hooks by creating a backup. You can use the Ark logs to verify that the pre and post | ||
hooks are running and exiting without error. | ||
|
||
```shell | ||
kubectl patch -n heptio-ark config default --type merge -p '{"restoreOnlyMode": false}' | ||
ark backup create nginx-hook-test | ||
|
||
ark backup get nginx-hook-test | ||
ark backup logs nginx-hook-test | grep hookCommand | ||
``` | ||
|
||
|
||
[1]: api-types/backup.md | ||
[2]: https://github.com/heptio/ark/blob/master/examples/nginx-app/with-pv.yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use |
||
[3]: cloud-common.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could apply all of these annotations in a single
kubectl
call, e.g.kubectl annotate pod a=b c=d ...
-- which I think would remove the need to flip ark into restore-only mode and back. I think that'd be preferable since although I get the restore-only mode thing, it distracts a little from the main point