[go: up one dir, main page]

0% found this document useful (0 votes)
12 views20 pages

03-Kubernetes Commands 101

The document provides an overview of essential Kubernetes commands, focusing on the 'kubectl' command-line tool. It includes syntax and examples for commands such as 'kubectl get', 'kubectl describe', 'kubectl logs', 'kubectl exec', and 'kubectl delete'. The document serves as a basic guide for users to manage Kubernetes resources effectively.

Uploaded by

Vicky Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views20 pages

03-Kubernetes Commands 101

The document provides an overview of essential Kubernetes commands, focusing on the 'kubectl' command-line tool. It includes syntax and examples for commands such as 'kubectl get', 'kubectl describe', 'kubectl logs', 'kubectl exec', and 'kubectl delete'. The document serves as a basic guide for users to manage Kubernetes resources effectively.

Uploaded by

Vicky Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Kubernetes Commands 101

August 2023
Aaron Kirn
Technical Leader - Cisco DNA Center
kubectl get

kubectl describe

Command kubectl logs


Agenda
kubectl exec

kubectl delete

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl get

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl get

Basic Syntax: kubectl get pods -n <namespace>

$ kubectl get pods -n ise


kubectl get pods NAME READY STATUS RESTARTS AGE
ise-bridge-744d8fb4dc-949t7 1/1 Running 4 (5d12h ago) 6d5h

$ kubectl get pods -n ai-network-analytics


kubectl get nodes NAME
apiproxy-7b8dffd446-xr2cg
READY
1/1
STATUS
Running
RESTARTS
1 (4d22h ago)
AGE
6d5h
kairos-agent-7dcb7f785b-h9qzs 1/1 Running 0 6d5h

$ kubectl get pods -A


kubectl get services NAMESPACE
ai-network-analytics
NAME
apiproxy-7b8dffd446-xr2cg
READY
1/1
STATUS
Running
RESTARTS
1 (4d22h ago)
AGE
6d5h
ai-network-analytics kairos-agent-7dcb7f785b-h9qzs 1/1 Running 0 6d5h
assurance-backend asc-57ab0bb6-jm-db4b49d9f-7t6qs 1/1 Running 4 (5d13h ago) 6d5h
assurance-backend asc-assurance-1-57ab0bb6-tm-6ff675579b-v76vn 1/1 Running 5 (5d13h ago) 6d5h
assurance-backend asc-assurance-2-57ab0bb6-tm-58766f848d-gcvp9 1/1 Running 5 (5d13h ago) 6d5h
assurance-backend asc-base-57ab0bb6-tm-84647fb644-dcxk5 1/1 Running 8 (5d13h ago) 6d5h
……

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl get

Basic Syntax: kubectl get nodes

$ kubectl get nodes


kubectl get pods NAME STATUS ROLES AGE VERSION
1.1.1.231 Ready master 3y201d v1.18.15-cisco
1.1.1.232 Ready master 3y201d v1.18.15-cisco
1.1.1.233 Ready master 3y201d v1.18.15-cisco

kubectl get nodes


$ kubectl get nodes 1.1.1.232
NAME STATUS ROLES AGE VERSION
1.1.1.232 Ready master 3y201d v1.18.15-cisco
kubectl get services

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl get

Basic Syntax: kubectl get services –n <namespace>

$ kubectl get services -n ai-network-analytics


kubectl get pods NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
apiproxy ClusterIP 169.254.54.243 <none> 8088/TCP,8001/TCP 6d6h
kairos-agent ClusterIP 169.254.57.110 <none> 8089/TCP,8001/TCP 6d6h

$ kubectl get services -n kube-system


kubectl get nodes
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dragoneye-vm-coredns ClusterIP None <none> 9153/TCP 6d8h
dragoneye-vm-kube-etcd ClusterIP None <none> 2323/TCP 6d8h
dragoneye-vm-kube-proxy ClusterIP None <none> 10249/TCP 6d8h
dragoneye-vm-kube-scheduler ClusterIP None <none> 10259/TCP 6d8h
etcd ClusterIP 169.254.59.85 <none> 4001/TCP,2323/TCP 6d9h
kube-dns ClusterIP 169.254.48.10 <none> 53/UDP,53/TCP,9153/TCP 6d9h
metrics-server ClusterIP 169.254.51.10 <none> 8443/TCP 6d9h

kubectl get services


$ kubectl get services -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ai-network-analytics apiproxy ClusterIP 169.254.54.243 <none> 8088/TCP,8001/TCP 6d6h
ai-network-analytics kairos-agent ClusterIP 169.254.57.110 <none> 8089/TCP,8001/TCP 6d6h
assurance-backend nsa-webapp ClusterIP 169.254.57.9 <none> 8077/TCP 6d6h
……

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Basic Syntax: kubectl describe pod -n <namespace> <pod>

$ kubectl describe pod -n mks mksserver


Name: mksserver-6f6599f486-rthk8
Namespace: mks
Priority: 2000000000
Priority Class Name: system-cluster-critical
kubectl describe pod Node: 169.254.6.66/169.254.6.66
Start Time: Fri, 11 Aug 2023 01:02:41 +0000
Labels: pod-template-hash=6f6599f486
serviceName=mksserver
Annotations: cni.projectcalico.org/containerID:
12c0dbb85429ebe6388477e10182b83de03c92ccde96cd430cb9e951d38bc594
kubectl describe node cni.projectcalico.org/podIP: 169.254.38.136/32
cni.projectcalico.org/podIPs: 169.254.38.136/32
mks-etcd-cert-required: true
mks.cisco.com/config-defaulter: true
version: 2.3.62
Status: Running
IP: 169.254.38.136
IPs:
IP: 169.254.38.136
Controlled By: ReplicaSet/mksserver-6f6599f486
......

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Containers:
mksserver:
Container ID:
containerd://a1238a69f61a47a21a568f20f2f36bfa90ff2447c6a15978204f3d76a93fc930
Image: catalogsvc-reg.ciscoconnectdna.com/maglev-
docker/mksserver:2.3.60
Image ID:
sha256:031527165763b4863a463b2ac45d9a68a020a10f01999fff355870bcb67b89ff
kubectl describe pod Port: 8017/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 11 Aug 2023 01:03:05 +0000
Ready: True
Restart Count: 0
kubectl describe node Limits:
cpu: 1
memory: 1Gi
Requests:
cpu: 100m
memory: 250Mi
Liveness: http-get https://:8017/api/services/mksserver/status delay=60s
timeout=10s period=30s #success=1 #failure=3
Environment:
K8S: true
......

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
api-features:
kubectl describe pod Type: ConfigMap (a volume populated by a ConfigMap)
Name: api-features
Optional: true
[…]
QoS Class: Burstable
Node-Selectors: <none>
kubectl describe node Tolerations: :NoSchedule op=Exists
node.kubernetes.io/not-ready:NoExecute op=Exists for
300s
node.kubernetes.io/unreachable:NoExecute op=Exists for
300s
Events: <none>

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Basic Syntax: kubectl describe node <name>
$ kubectl describe node 169.254.6.66
Name: 169.254.6.66
Roles: control-plane
Labels: allAppstacks=enabled
appstack.maglev-system=enabled
[…]
Annotations: kubeadm.alpha.kubernetes.io/cri-socket: unix:///run/containerd/containerd.sock
node.alpha.kubernetes.io/ttl: 0
kubectl describe pod […]
CreationTimestamp: Thu, 10 Aug 2023 05:13:41 +0000
Taints: <none>
Unschedulable: false
Lease:
HolderIdentity: 169.254.6.66
AcquireTime: <unset>

kubectl describe node RenewTime:


Conditions:
Mon, 21 Aug 2023 14:25:00 +0000

Type Status LastHeartbeatTime LastTransitionTime Reason


Message
---- ------ ----------------- ------------------ ------
-------
NetworkUnavailable False Fri, 11 Aug 2023 01:00:49 +0000 Fri, 11 Aug 2023 01:00:49 +0000 CalicoIsUp
Calico is running on this node
MemoryPressure False Mon, 21 Aug 2023 14:25:00 +0000 Thu, 10 Aug 2023 05:13:38 +0000 KubeletHasSufficientMemory
kubelet has sufficient memory available
DiskPressure False Mon, 21 Aug 2023 14:25:00 +0000 Thu, 10 Aug 2023 05:13:38 +0000 KubeletHasNoDiskPressure
kubelet has no disk pressure
PIDPressure False Mon, 21 Aug 2023 14:25:00 +0000 Thu, 10 Aug 2023 05:13:38 +0000 KubeletHasSufficientPID
kubelet has sufficient PID available
Ready True Mon, 21 Aug 2023 14:25:00 +0000 Fri, 11 Aug 2023 01:07:30 +0000 KubeletReady
kubelet is posting ready status

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Addresses:
InternalIP: 169.254.6.66
Hostname: 169.254.6.66
Capacity:
cpu: 32
[…]
Allocatable:
cpu: 30
[…]
System Info:

kubectl describe pod


Machine ID: 7def5aad3b39463a96e3239d2573df43
System UUID: e4dc3942-653b-ca13-6b71-747d0171b508
Boot ID: 96949ad3-46f4-49b9-be93-d3ecec67c0bc
Kernel Version: 5.4.0-139-generic
OS Image: Ubuntu 18.04.6 LTS
Operating System: linux
Architecture: amd64
Container Runtime Version: containerd://1.6.6
kubectl describe node Kubelet Version:
Kube-Proxy Version:
v1.24.1-cisco
v1.24.1-cisco
Non-terminated Pods: (148 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory
Limits Age
--------- ---- ------------ ---------- --------------- -----------
-- ---
ai-network-analytics apiproxy-7b8dffd446-xr2cg 50m (0%) 300m (1%) 256Mi (0%) 512Mi (0%)
11d
ai-network-analytics kairos-agent-7dcb7f785b-h9qzs 50m (0%) 2700m (9%) 768Mi (0%) 3584Mi (1%)
11d
assurance-backend asc-57ab0bb6-jm-db4b49d9f-7t6qs 50m (0%) 2 (6%) 2Gi (0%) 2Gi (0%)
11d
……

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl describe
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 27640m (92%) 171198m (570%)
memory 176588Mi (73%) 397033Mi (164%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-1Gi 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
kubectl describe pod Events: <none>

kubectl describe node

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl logs
kubectl exec
kubectl delete

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl logs, exec, and delete

Basic Syntax: kubectl logs -n <namespace> <pod>


$ kubectl logs -n kube-system etcd-169.254.6.66
kubectl logs Defaulted container "etcd" out of: etcd, decrypt-private-key (init)
{"level":"info","ts":"2023-08-11T00:55:10.041Z","caller":“
etcdmain/etcd.go:73","msg":"Running:","args":["/usr/local/bin/etcd","--data-
dir=/var/lib/etcd"]}
{"level":"warn","ts":"2023-08-11T00:55:10.044Z","caller":"etcdmain/etcd.go:446","msg":"found
invalid file under data directory","filename":"lost+found","data-dir":"/var/lib/etcd"}

$ kubectl logs -n fusion postgres-0 -c postgres


kubectl exec 2023-08-17 02:06:58.462 UTC [24524] ERROR: duplicate key value violates unique constraint
"index_1"
2023-08-17 02:06:58.462 UTC [24524] DETAIL: Key (protocol_name)=(XMPBootstrapHelper)
already exists.
2023-08-17 02:06:58.462 UTC [24524] STATEMENT: INSERT INTO protocol (PROTOCOL_NAME,
PROTOCOL_ID) values ($1, nextval('credential_mgr_seq'))
2023-08-17 02:07:00.223 UTC [24524] ERROR: syntax error at or near ")" at character 3486

kubectl delete $ kubectl logs -n fusion data-cob-rshgp -c data-cob -p


{"instant":{"epochSecond":1691716132,"nanoOfSecond":438685000},"thread":"main","level":"ERRO
R","loggerName":"com.cisco.enc.common.aspects.MessageListenerShutDownAspect","message":"AMQP
consumer shut down. Exit the system as no consumer is attached
anymore!","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","contextMap
":{"requestId":"","tenantId":"TNT0"},"threadId":1,"threadPriority":5}

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl logs, exec, and delete
Basic Syntax: kubectl exec -it -n <namespace> <pod> -- <command>

$ kubectl exec -it -n fusion file-service-56cd89c74b-wz2kv -- /bin/bash


kubectl logs Defaulted container "file-service" out of: file-service, chgperms (init)
maglev@file-service-56cd89c74b-wz2kv:/$ hostname
file-service-56cd89c74b-wz2kv
maglev@file-service-56cd89c74b-wz2kv:/$

$ kubectl exec -it -n fusion file-service-56cd89c74b-wz2kv -- hostname


Defaulted container "file-service" out of: file-service, chgperms (init)
file-service-56cd89c74b-wz2kv
kubectl exec $

$ kubectl exec -it -n fusion postgres-0 -c postgres -- psql -d campus -U


appuser
psql (11.5 (Debian 11.5-3.pgdg90+1))
Type "help" for help.
campus=#

kubectl delete $ kubectl exec -it -n fusion postgres-0 -c postgres -- psql -d campus -U
appuser -c "select * from pkibrokerconfig;"
id | instance_version | instanceuuid | displayname | pkiconfig | authentityid
-------+------------------+------------------------+-------------+--------------------------
35035 | 0 | iostruststore-password |

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
kubectl logs, exec, and delete

Basic Syntax: kubectl delete pod -n <namespace> <pod>


$ kubectl delete pod -n managed-services-shared rabbitmq-0
kubectl logs pod “rabbitmq-0” deleted

$ kubectl get pods -A | grep rabbit


NAMESPACE NAME READY Status RESTARTS AGE
managed-services-shared rabbitmq-0 0/1 Init:0/1 0 5s

kubectl exec $ kubectl get pods -A | grep rabbit


NAMESPACE NAME READY Status RESTARTS AGE
managed-services-shared rabbitmq-0 1/1 Running 0 4m

kubectl delete

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
Resources

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential
Resources

TechZone: Cisco DNA Center MKS 3.0 CLI Command Changes

IT Wiki: OnPrem VM Commands

Kubernetes.io: kubectl Cheat Sheet

© 2023 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco Confidential

You might also like