{"id":14008207,"url":"https://github.com/errordeveloper/kubeplay","last_synced_at":"2025-10-23T02:33:30.329Z","repository":{"id":137924945,"uuid":"76476714","full_name":"errordeveloper/kubeplay","owner":"errordeveloper","description":"kubeplay – a new way to interact with Kubernetes API from your terminal","archived":false,"fork":false,"pushed_at":"2018-07-24T03:15:09.000Z","size":11403,"stargazers_count":86,"open_issues_count":3,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T08:43:32.358Z","etag":null,"topics":["dsl","kubectl","kubernetes","repl","ruby"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/errordeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-14T16:23:21.000Z","updated_at":"2024-08-13T08:53:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"82a20281-83c7-4d30-82e5-6c01d25b871f","html_url":"https://github.com/errordeveloper/kubeplay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errordeveloper%2Fkubeplay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errordeveloper%2Fkubeplay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errordeveloper%2Fkubeplay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errordeveloper%2Fkubeplay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/errordeveloper","download_url":"https://codeload.github.com/errordeveloper/kubeplay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249715461,"owners_count":21315052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","kubectl","kubernetes","repl","ruby"],"created_at":"2024-08-10T11:01:25.016Z","updated_at":"2025-10-23T02:33:30.006Z","avatar_url":"https://github.com/errordeveloper.png","language":"Go","readme":"# `kubeplay` – a new way to interact with Kubernetes\n\n\u003e NOTE: _this project is still in an early stage_\n\n\u003e If you like this project, please checkout [TODOs](#todos) and open an issue if you'd like to contribute or discuss anything in particular.\n\n## Usage example: easy REPL with Ruby syntax\n\n```console\n\u003e ./kubeplay\nkubeplay (namespace=\"*\")\u003e pods # list pods in the cluster\n\u003clist-of-pods\u003e\nkubeplay (namespace=\"*\")\u003e @pod = _.any # pick a random pod from the list\nkubeplay (namespace=\"*\")\u003e puts @pod.to_json # output the pod definition in JSON\n{\n  \"metadata\": {\n    ...\n  },\n  \"spec\": {\n    ...\n    \"containers\": [\n      {\n        ...\n      }\n    ],\n  },\n  \"status\": {\n    ...\n  }\n}\nkubeplay (namespace=\"*\")\u003e puts @pod.to_ruby # output the same as a Ruby hash\n{ ... }\nkubeplay (namespace=\"*\")\u003e @pod.delete! # I am a chaos monkey :)\n```\n\n## Resource Verbs\n\nCurrently implemented verbs are the following:\n\n- `pods`\n- `services`\n- `replicasets`\n- `daemonsets`\n\nEach of these can be used with index operator, e.g. `services[10]`, as well as `first`, `last` and `any` methonds.\nAny resource object can be converted to a JSON string with `to_json` method, or a Ruby object with `to_ruby`.\n\nWith a Ruby object reprsentation you can do things like this:\n```ruby\n@metadata = replicasets(\"*/\").to_ruby.items.map do |k,v|\n   v.metadata\nend\n\n@metadata.each do |i|\n    puts \"Name:\\t#{i.name}\"\n    puts \"Labels:\\t#{i.labels}\"\n    puts\nend\n```\n\nYou can define a verb aliases with `def_alias`, e.g. to create an `rs` verb alias for `replicasets` use\n```Ruby\ndef_alias :rs, :replicasets\n```\n\nBy default a verb operates on all namespaces, hence `(namespace=\"*\")` is shown in the prompt.\nYou can switch current namespaces with `namespace` verb, e.g.\n```console\nkubeplay (namespace=\"*\")\u003e namespace \"kube-system\"\nkubeplay (namespace=\"kube-system\")\u003e\n```\nTo go back to all-namespaces mode, use `namespace \"*\"`.\n\n### Resource Arguments\n\nA verb may take up two arguments in any order - a glob string and a block or hash.\n\n#### TL;DR\n\nTo get all replica sets in `default` namespaces which have label `app` not matching `foo` or `bar` and label `version` matching `0.1` or `0.2` use\n\n```ruby\nreplicasets \"default/\", labels: -\u003e { @app !~ %w(foo bar) ; @version =~ %w(0.1 0.2) ; }\n```\n\nTo get all running pods with label `app` matching `foo` or `bar` use\n```ruby\npods { @app =~ %w(foo bar) ; status.phase == \"Running\" ; }\n```\n\n#### Glob Expressions\n\nHere are some examples illustrating the types of glob expressions that `kubeplay` understands.\n\nGet all pods in `kube-systems` namespace:\n```ruby\npods \"kube-system/\"\n```\n\nGet all pods in all namespace:\n```ruby\npods \"*/\"\n```\n\nGet all pods in current namespace with name matching `*foo*`:\n```ruby\npods \"*foo*\"\n```\n\nMore specifically, this enables getting pods in a namespace other then current like this:\n```console\nkubeplay (namespace=\"default\")\u003e pods \"kube-system/foo-*\"\n```\nOr, gettin pods with name matching `\"bar-*` in all namespace like this:\n```console\nkubeplay (namespace=\"default\")\u003e pods \"*/bar-*\"\n```\n\n\u003e NOTE: if current namespace is `\"*\"`, `pods \"*\"` is the same as `pods`; `pods \"*/*\"` is always the same as `pods \"*/\"`.\n\n#### Label \u0026 Field Selectors\n\nAnother argument a resource verb understand is a block specifying label and field selectors using special syntax outlined below.\n\n##### Label Selector Syntax\n\nTo match a label agains a set of values, use `label(\"name\") =~ %w(foo bar)`, or `!~`.\n\nIf you want to just get resources with a certain label to set anything, use `label(\"baz\").defined?`\n\nThis\n```ruby\n{\n  label(\"name\") =~ %w(foo bar)\n  label(\"baz\").defined?\n}\n```\nwill compile a selector string `name in (foo, bar),myapp`.\n\nAnd this\n```ruby\n{\n  label(\"name\") !~ %w(foo bar)\n  label(\"baz\").defined?\n}\n```\nwill compile a selector string `name notin (foo, bar),myapp`.\n\nSome well-known labels have shortuct, e.g.\n```ruby\n{\n  @app !~ %w(foo bar)\n  @version =~ %w(0.1 0.2)\n  @tier =~ %w(frontend backend)\n}\n```\n\nSimply pass a block like this:\n```ruby\nreplicasets { @app !~ %w(foo bar); @version =~ %w(0.1 0.2); @tier =~ %w(frontend backend); }\n```\n\nYou can also use `make_label_selector` verb to construct these expressions and save those to variabels etc.\n\n##### Field Selector Syntax\n\nThis syntax is different, yet somewhat simpler.\n\nHere is a selector mathing all running pods:\n```ruby\n{ status.phase != :Running }\n```\n\n#### Using Slectors\n\nTo get all running pods with label `tier` mathcing `backend`:\n```ruby\npods { status.phase != :Running ; @tier =~ \"backend\" ; }\n```\n\nAlternatively, if you prefer to be more explicit, you can use a hash:\n```ruby\npods fields: -\u003e { status.phase != :Running }, labels: -\u003e { @tier =~ \"backend\" }\n```\n\nYou can also use compose selector expressions diretly as strings, if you prefer:\n```ruby\npods fields: \"status.phase != Running\", labels: \"tier in (backend)\"\n```\n\n### Inspecting the Logs\n\nTo get grep logs for any pod matching given selector\n\n```ruby\npods{ @name =~ \"launch-generator\" ; }.any.logs.grep \".*INFO:.*\", \".*user-agent:.*\"\n```\n\n## Usage example: object generator with minimal input\n\n```console\n\u003e ./kubeplay -kubeconfig ~/.kube/config\nkubeplay (namespace=\"*\")\u003e @pod = make_pod(image: \"errordeveloper/foo:latest\")\nkubeplay (namespace=\"*\")\u003e puts _.to_json\n{\n  \"metadata\": {\n    \"creationTimestamp\": null,\n    \"labels\": {\n      \"name\": \"foo\"\n    }\n  },\n  \"spec\": {\n    \"containers\": [\n      {\n        \"name\": \"foo\",\n        \"image\": \"errordeveloper/foo:latest\",\n        \"resources\": {}\n      }\n    ]\n  },\n  \"status\": {}\n}\nkubeplay (namespace=\"*\")\u003e @pod.create!\nkubeplay (namespace=\"*\")\u003e @pod.delete!\n\nkubeplay (namespace=\"*\")\u003e ^D\n\u003e\n```\n\n### TODOs\n\nHere are some TODO items and ideas.\n\n- [x] `pod.delete!`\n- [x] `pod.create!`\n- [x] `pod.logs` \u0026 `pod.logs.grep`\n- [x] `pods.logs` \u0026 `pods.logs.grep`\n- [ ] `pod.logs.pager` and `pod.logs.grep.pager`\n- [ ] grep logs in any set of resources\n- [ ] more fluent behaviour of set resources, e.g. `replicasets.pods` and not `replicasets.any.pods`\n- [ ] reverse lookup, e.g. given `@rs = replicasets.any`, `@rs.pods.any.owner` should be the same as `@rs`\n- [ ] way to run scripts and not just REPL\n- [ ] extend resource generator functionality\n  - [ ] `ReplicaSet`+`Service`\n  - [ ] `Kubefile` DSL\n\n#### Ideas\n\n  - simple framework for controllers and 3rd-party resource (e.g. chaos monkey of sorts, or use terraform to create an exteranl resource and store URL in a secret, custom policy controller made easy)\n  - multi-cluster support\n  - resource diff\n  - network policy tester framework\n  - eval/exec code in a pod\n  - test framework for apps, e.g. \"Here is my app, it has a configmap and a secrete, and I want to test if it works\"\n\n### Building\n\nGet the source code and build the dependencies:\n\n```bash\ngo get github.com/Masterminds/glide\ngo get -d github.com/errordeveloper/kubeplay\ncd $GOPATH/src/github.com/errordeveloper/kubeplay\n$GOPATH/bin/glide up -v\nmake -C vendor/github.com/mitchellh/go-mruby libmruby.a\ngo install ./rubykube\n```\n\nBuild `kubeplay`:\n```bash\ngo build .\n```\n\n### Credits\n\nThe mruby integration was inspired by [@erikh's box](https://github.com/erikh/box), and some of the code was initially copied from there.\n","funding_links":[],"categories":["API/CLI adaptors","Go"],"sub_categories":["[Jenkins](#jenkins)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrordeveloper%2Fkubeplay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferrordeveloper%2Fkubeplay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrordeveloper%2Fkubeplay/lists"}