Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

policygen

A small CLI tool that spits out Kubernetes NetworkPolicy YAML so you don't have to hand-write it every time.

I got tired of copy-pasting the same NetworkPolicy boilerplate and tweaking labels/namespaces by hand, so this just generates it for you. Right now it supports building a policy by label selector, more match types are on the list.

Why

Writing a NetworkPolicy manifest from scratch is one of those things that's simple but annoying, easy to typo the indentation, easy to forget policyTypes. This just handles that part so you can move on.

Install

git clone https://github.com/jhash1/policygen.git
cd policygen
go build

(You'll need Go installed — nothing fancy, whatever recent-ish version.)

Usage

go run policygen --name appnetworkpolicy --namespace testing --labels app=nginx

That gives you something like:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: appnetworkpolicy
  namespace: testing
spec:
  podSelector:
    matchLabels:
      app: nginx
  policyTypes:
    - Ingress
    - Egress

Flags

Flag What it does
--name name of the NetworkPolicy
--namespace namespace it lives in
--labels label selector, e.g. app=nginx

Pipe the output straight into kubectl apply -f - if you trust it, or redirect it to a file first if you want to eyeball it (probably the smarter move).

Status

This is a personal project I'm actively poking at, not a polished tool with a stable API, flags and output might shift around. Label-based selection works today; more selector types and policy shapes are coming when I get to them.

About

CLI utility -Network Policy Generator for Kubernetes (Personal Project)

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages