restart-object can restart Kubernetes' Deployment / DaemonSet / StatefulSet. It is intended to be run as a Kubernetes Job or CronJob and to restart Deployment. Please add "imagePullPolicy: Always" to Pod.
Assumed to be used to restart the Pod running in the development environment with the latest image tags.
Note: Do not use the latest image tag in a production environment.
restart-object was created referring to the kubectl rollout restart
command.
Realize restart by giving annotation kubectl.kubernetes.io/restartedAt
for podTemplateSpec.
I have a motivation to periodically Deploy latest image the development environment application. In GitOps, Git is a single source of truth. So to deploy a new image you have to rewrite the manifests image tag and commit it to Git. But the logic to monitor the image registry and commit it to Git is complicated. I developed restart-object as a mechanism to realize this task easily.
Build restart-object:
$ make build
and run restart-object:
$ ./dist/restart-object --tag latest --namespace nginx
For more information about available options run:
$ ./dist/restart-object --help
Restart Kubernetes Object
Usage:
restart-object [flags]
restart-object [command]
Available Commands:
help Help about any command
version Show version
Flags:
--disable strings Disable objects names
--disable-all Disable all objects
--enable strings Enable objects names
--enable-all Enable all objects
-h, --help help for restart-object
--in-cluster Execute for in Kubernetes cluster
--namespace string Namespace (default "default")
--objects string Restart objects (default "deployment")
--tag string Target to restart image tag name (default "latest")
Use "restart-object [command] --help" for more information about a command.
restart-object can be run as a Job inside of a Pod.
$ kubectl apply -f ./examples/manifests/restart-object.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: restart-object-job
spec:
completions: 1
parallelism: 1
template:
spec:
serviceAccountName: restart-object
containers:
- name: restart-object-job
image: daikurosawa/restart-object:v0.0.2
command:
- ./restart-object
- --in-cluster=true
- --tag=latest
restartPolicy: Never
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: restart-object
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: restart-object
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: restart-object
subjects:
- kind: ServiceAccount
name: restart-object
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: restart-object
rules:
- apiGroups: ["apps"]
resources: ["deployments", "daemonsets"]
verbs: ["list", "patch"]
- apiGroups: ["extensions"]
resources: ["deployments", "daemonsets"]
verbs: ["list", "patch"]
- Support StatefulSet restart
- Add tests
- Support server side apply