Skip to content

Commit

Permalink
Add support to read resources from kubernetes manifests. Closes #128 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Subhajit97 committed May 23, 2023
1 parent 2e444db commit 305aad2
Show file tree
Hide file tree
Showing 76 changed files with 4,523 additions and 810 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@

install:
go build -o ~/.steampipe/plugins/hub.steampipe.io/plugins/turbot/kubernetes@latest/steampipe-plugin-kubernetes.plugin *.go


go build -o ~/.steampipe/plugins/hub.steampipe.io/plugins/turbot/kubernetes@latest/steampipe-plugin-kubernetes.plugin *.go
102 changes: 95 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,104 @@ Use SQL to query Kubernetes components.

## Quick start

Install the plugin with [Steampipe](https://steampipe.io):
### Install

```shell
Download and install the latest Kubernetes plugin:

```bash
steampipe plugin install kubernetes
```

Run a query:
Configure your [config file](https://hub.steampipe.io/plugins/turbot/kubernetes#configuration).

```hcl
connection "kubernetes" {
plugin = "kubernetes"
# By default, the plugin will use credentials in "~/.kube/config" with the current context.
# OpenID Connect (OIDC) authentication is supported without any extra configuration.
# The kubeconfig path and context can also be specified with the following config arguments:
# Specify the file path to the kubeconfig.
# Can also be set with the "KUBE_CONFIG_PATHS" or "KUBERNETES_MASTER" environment variables.
# config_path = "~/.kube/config"
# Specify a context other than the current one.
# config_context = "minikube"
# List of custom resources that will be created as dynamic tables.
# No dynamic tables will be created if this arg is empty or not set.
# Wildcard based searches are supported.
# For example:
# - "*" matches all custom resources available
# - "*.storage.k8s.io" matches all custom resources in the storage.k8s.io group
# - "certificates.cert-manager.io" matches a specific custom resource "certificates.cert-manager.io"
# - "backendconfig" matches the singular name "backendconfig" in any group
# Defaults to all custom resources
custom_resource_tables = ["*"]
# If no kubeconfig file can be found, the plugin will attempt to use the service account Kubernetes gives to pods.
# This authentication method is intended for clients that expect to be running inside a pod running on Kubernetes.
# Manifest file paths is a list of locations to search for Kubernetes manifest files
# Manifest file paths can be configured with a local directory, a remote Git repository URL, or an S3 bucket URL
# Refer https://hub.steampipe.io/plugins/turbot/kubernetes#supported-path-formats for more information
# Wildcard based searches are supported, including recursive searches
# Local paths are resolved relative to the current working directory (CWD)
# For example:
# - "*.yml" matches all Kubernetes manifest files in the CWD
# - "**/*.yml" matches all Kubernetes manifest files in the CWD and all sub-directories
# - "../*.yml" matches all Kubernetes manifest files in the CWD's parent directory
# - "steampipe*.yml" matches all Kubernetes manifest files starting with "steampipe" in the CWD
# - "/path/to/dir/*.yml" matches all Kubernetes manifest files in a specific directory
# - "/path/to/dir/main.yml" matches a specific file
# If the given paths includes "*", all files (including non-kubernetes manifest files) in
# the CWD will be matched, which may cause errors if incompatible file types exist
# Defaults to CWD
# manifest_file_paths = [ "*.yml", "*.yaml" ]
# Specify the source of the resource. Possible values: `deployed`, `manifest`, and `all`.
# Default set to `all`. Set the argument to override the default value.
# If the value is set to `deployed`, tables will show all the deployed resources.
# If set to `manifest`, tables will show all the resources from the kubernetes manifest. Make sure that the `manifest_file_paths` arg is set.
# If `all`, tables will show all the deployed and manifest resources.
# source_type = "all"
}
```

Run steampipe:

```shell
steampipe query
```

List all pods:

```sql
select name, creation_timestamp, addresses, capacity from kubernetes_node;
select
name,
namespace,
phase,
creation_timestamp,
pod_ip
from
kubernetes_pod;
```

```sh
+-----------------------------------------+-------------+-----------+---------------------+-----------+
| name | namespace | phase | creation_timestamp | pod_ip |
+-----------------------------------------+-------------+-----------+---------------------+-----------+
| metrics-server-86cbb8457f-bf8dm | kube-system | Running | 2021-06-11 14:21:48 | 10.42.0.5 |
| coredns-7448499f4d-klb8l | kube-system | Running | 2021-06-11 14:21:48 | 10.42.0.6 |
| helm-install-traefik-crd-hb87d | kube-system | Succeeded | 2021-06-11 14:21:48 | 10.42.0.3 |
| local-path-provisioner-5ff76fc89d-c9hnm | kube-system | Running | 2021-06-11 14:21:48 | 10.42.0.2 |
+-----------------------------------------+-------------+-----------+---------------------+-----------+
```

## Developing
Expand All @@ -39,20 +127,20 @@ cd steampipe-plugin-kubernetes

Build, which automatically installs the new version to your `~/.steampipe/plugins` directory:

```
```sh
make
```

Configure the plugin:

```
```shell
cp config/* ~/.steampipe/config
vi ~/.steampipe/config/kubernetes.spc
```

Try it!

```
```shell
steampipe query
> .inspect kubernetes
```
Expand Down
27 changes: 27 additions & 0 deletions config/kubernetes.spc
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,31 @@ connection "kubernetes" {

# If no kubeconfig file can be found, the plugin will attempt to use the service account Kubernetes gives to pods.
# This authentication method is intended for clients that expect to be running inside a pod running on Kubernetes.

# Manifest file paths is a list of locations to search for Kubernetes manifest files
# Manifest file paths can be configured with a local directory, a remote Git repository URL, or an S3 bucket URL
# Refer https://hub.steampipe.io/plugins/turbot/kubernetes#supported-path-formats for more information
# Wildcard based searches are supported, including recursive searches
# Local paths are resolved relative to the current working directory (CWD)

# For example:
# - "*.yml" matches all Kubernetes manifest files in the CWD
# - "**/*.yml" matches all Kubernetes manifest files in the CWD and all sub-directories
# - "../*.yml" matches all Kubernetes manifest files in the CWD's parent directory
# - "steampipe*.yml" matches all Kubernetes manifest files starting with "steampipe" in the CWD
# - "/path/to/dir/*.yml" matches all Kubernetes manifest files in a specific directory
# - "/path/to/dir/main.yml" matches a specific file

# If the given paths includes "*", all files (including non-kubernetes manifest files) in
# the CWD will be matched, which may cause errors if incompatible file types exist

# Defaults to CWD
# manifest_file_paths = [ "*.yml", "*.yaml" ]

# Specify the source of the resource. Possible values: `deployed`, `manifest`, and `all`.
# Default set to `all`. Set the argument to override the default value.
# If the value is set to `deployed`, tables will show all the deployed resources.
# If set to `manifest`, tables will show all the resources from the kubernetes manifest. Make sure that the `manifest_file_paths` arg is set.
# If `all`, tables will show all the deployed and manifest resources.
# source_type = "all"
}
Loading

0 comments on commit 305aad2

Please sign in to comment.