restart-object

command module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

README

restart-object

CircleCI Go Report Card

About restart-object

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.

Why restart Pod with CronJob ?

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 and Run

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.

Running restart-object as a Job Inside of a Pod

restart-object can be run as a Job inside of a Pod.

Run the restart-object as a Job in a Pod:
$ kubectl apply -f ./examples/manifests/restart-object.yaml
Manifests examples
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"]

TODO

  • Support StatefulSet restart
  • Add tests
  • Support server side apply

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL