kubectl
How to pronounce?
- kube ctl
- kube control
Configuration
example ~/.kube/config
# two clusters, two users, and three contexts:
apiVersion: v1
clusters:
- cluster:
certificate-authority: fake-ca-file
server: https://1.2.3.4
name: development
- cluster:
insecure-skip-tls-verify: true
server: https://5.6.7.8
name: scratch
contexts:
- context:
cluster: development
namespace: frontend
user: developer
name: dev-frontend
- context:
cluster: development
namespace: storage
user: developer
name: dev-storage
- context:
cluster: scratch
namespace: default
user: experimenter
name: exp-scratch
current-context: ""
kind: Config
preferences: {}
users:
- name: developer
user:
client-certificate: fake-cert-file
client-key: fake-key-file
- name: experimenter
user:
password: some-password
username: exp
Configuration
context = (cluster, user, namespace)
# set current context
kubectl config --kubeconfig=config-demo use-context dev-frontend
# get all contexts
kubectl config get-contexts
# get current context
kubectl config current-context
Syntax
kubectl [command] [TYPE] [NAME] [flags]
-
command: Specifies the operation that you want to perform on one or more resources, for example create, get, describe, delete.
- TYPE: Specifies the resource type. Resource types are case-insensitive and you can specify the singular, plural, or abbreviated forms.
-
NAME: Specifies the name of the resource. Names are case-sensitive. If the name is omitted, details for all resources are displayed, for example kubectl get pods.
Other examples
# run bash interactively on pod
kubectl exec -it mypod bash
# run django shell interactively on pod
kubectl exec -it mypod python manage.py shell
# stream logs for all objects with label
kubectl logs -f -l app=myapp-label
# stream logs for all containers within deployment
kubectl logs -f deployment/<app-name> --all-containers=true --since=10m
kubectl the end
kubectl
By zqzak
kubectl
- 225