Skip to main content

kubectl python plugin

Project description

kubectl python plugin https://github.com/newpi6/kubectl-show.git

kubectl-show

A kubectl Plugin with Python

Install

pip install kubectl-show

Version 22.1.0.14

  • 22为kubernetes sdk主版本,22支持k8s版本1.21-1.23

Usage

kubectl-show [command] [sub-command] [flags]

以kubectl插件的方式运行:kubectl show [command] [sub-command] [flags]

command and sub-command

  • q|query image|count 查询pod容器镜像|统计
  • g|generate template [-k|--kind] 生成不同资源的yaml文件

flags

  • -A all namespace,--ALL, bool,指定该参数则为true
  • -n namespace,--namespace
  • -k svc,pod,..., --kind 指定资源类型,资源类型名称与k8s一直,支持缩写
  • -f github|plain..., table format, --fmt 输出格式化

参考tabulate

  • -i , table index, --index, 输出增加行号,query(command)中有效
  • -s "xx", --strip, 输出镜像信息时将该字符串替换为空,query(command)中有效

example

kubectl show q images

# kubectl-show q images
namespace    pod name                               container name , image                        pod status    container status
default      apple-app                              [['apple-app', 'hashicorp/http-echo']]        Running       ['Ready']
default      banana-app                             [['banana-app', 'hashicorp/http-echo']]       Running       ['Ready']
default      kubernetes-downwardapi-volume-example  [['client-container', 'k8s.gcr.io/busybox']]  Running       ['Ready']
default      nginx-7b57989df-6q59k                  [['nginx', 'nginx']]                          Running       ['Ready']
# kubectl-show q images -A -f github
| namespace            | pod name                                  | container name , image                                                                                  | pod status   | container status           |
|----------------------|-------------------------------------------|---------------------------------------------------------------------------------------------------------|--------------|----------------------------|
| argo                 | argo-server-79bf45b5b7-qkn9z              | [['argo-server', 'quay.io/argoproj/argocli:latest']]                                                    | Running      | ['Ready']                  |
| argo                 | workflow-controller-64d4785c88-497xx      | [['workflow-controller', 'quay.io/argoproj/workflow-controller:latest']]                                | Running      | ['Ready']                  |
| default              | apple-app                                 | [['apple-app', 'hashicorp/http-echo']]                                                                  | Running      | ['Ready']                  |
| default              | banana-app                                | [['banana-app', 'hashicorp/http-echo']]                                                                 | Running      | ['Ready']                  |
| default              | kubernetes-downwardapi-volume-example     | [['client-container', 'k8s.gcr.io/busybox']]                                                            | Running      | ['Ready']                  |
| default              | nginx-7b57989df-6q59k                     | [['nginx', 'nginx']]                                                                                    | Running      | ['Ready']                  |
| istio-system         | grafana-64b4b8f789-fkzld                  | [['grafana', 'grafana/grafana:6.5.2']]                                                                  | Running      | ['Ready']                  |
| istio-system         | istio-egressgateway-6c9778c57c-tt6xs      | [['istio-proxy', 'docker.io/istio/proxyv2:1.5.0']]                                                      | Pending      | ['Not Ready']

kubectl-show query count

kubectl-show query count -A -k pod,deployment,rc,svc,cm
namespace               pod    deployment    replicaset    service    configmap
all-namespaces           23            12            12         20           27
argo                      2             2             2          2            2
default                   4             1             1          4            1
istio-system              6             6             6         11           12
kube-node-lease           0             0             0          0            1
kube-public               0             0             0          0            2
kube-system               9             1             1          1            6
kubernetes-dashboard      2             2             2          2            2
operator                  0             0             0          0            1

kubectl-show g template

# kubectl-show g template  --name test-app --namespace default --replicas 3 -k deployment,svc
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
namespace: default
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
spec:
imagePullSecrets: []
nodeSelector: {}
#node.type: db
tolerations: []
#- key: "only"
#  operator: "Equal"
#  value: "db"
#  effect: "NoSchedule"
affinity:
podAntiAffinity: {}
nodeAffinity: {}
volumes: []
#- name: postgres
#  hostPath:
#    path: /data/middleware-data/postgres-data
#    type: DirectoryOrCreate
containers:
- image: test-app
imagePullPolicy: IfNotPresent
name: test-app
args: []
env: []
ports:
- containerPort: 80
name: http
volumeMounts: []
#- name: postgres
#  subPath: postgres
#  mountPath: /var/lib/postgresql/data
resources:
requests:
memory: 50Mi
cpu: 100m
ephemeral-storage: "2Gi"
limits:
memory: 50Mi
cpu: 100m
ephemeral-storage: "10Gi"
---
apiVersion: v1
kind: Service
metadata:
name: test-app
namespace: default
spec:
selector:
app: test-app
ports:
- protocol: TCP
port: 80
targetPort: http
type: NodePort

生成yaml配置并创建资源

kubectl-show g template --name test-app --namespace default --replicas 3 -k deployment,svc | kubectl create -f -

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubectl-show-22.1.0.23.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubectl_show-22.1.0.23-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file kubectl-show-22.1.0.23.tar.gz.

File metadata

  • Download URL: kubectl-show-22.1.0.23.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for kubectl-show-22.1.0.23.tar.gz
Algorithm Hash digest
SHA256 76e978a404975aed4fd849f4f2c77c88b0026c6596c61bfc91e3cd24de736364
MD5 76ea10f0f37731f4071bc1bead341cd6
BLAKE2b-256 3f94634cf99ca07c6693d95cd8987b01ff62ec72a9577efaca4e3b5cef4b1b83

See more details on using hashes here.

File details

Details for the file kubectl_show-22.1.0.23-py3-none-any.whl.

File metadata

File hashes

Hashes for kubectl_show-22.1.0.23-py3-none-any.whl
Algorithm Hash digest
SHA256 50423e5cff47843f48f0f36e2b000291d6980181f5260f56ae80fbb457ea560a
MD5 b9cff83bf2a78ea9be112fd86f1ee5f1
BLAKE2b-256 837cff778ec3f511b6544cdbd49987173fde0bae1cac90b42143915c05bc0660

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page