Cluster hakkında bilgi almak ve incelemek için aşağıdaki komutu kullanacağız, Hangi cluster üzerinde çalıştığımız hakkında da bilgi almamıza faydalı olacaktır,
root@kkubectl cluster-info root@k8s-c1-cp1:~# kubectl cluster-info Kubernetes control plane is running at https://172.22.17.200:6443 CoreDNS is running at https://172.22.17.200:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. root@k8s-c1-cp1:~#
Sık kullanacağımız en önemli işlemlerden bir tanesi.. Nodeların durumunu, sürümlerini gözlemlememize yardımcı olacak,
root@k8s-c1-cp1:~# kubectl get nodes NAME STATUS ROLES AGE VERSION c1-node1 Ready worker 9h v1.22.4 c1-node2 Ready worker 8h v1.22.4 c1-node3 Ready worker 8h v1.22.4 k8s-c1-cp1 Ready control-plane,master 9h v1.22.4 root@k8s-c1-cp1:~#
Bir cluster hakkında daha fazla bilgi (çıktı) almak için kullanabiliriz. Clusterdaki her node hakkında bilgi verir.
root@k8s-c1-cp1:~# kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME c1-node1 Ready worker 9h v1.22.4 172.22.17.201 <none> Ubuntu 21.04 5.11.0-49-generic containerd://1.5.5 c1-node2 Ready worker 8h v1.22.4 172.22.17.202 <none> Ubuntu 21.04 5.11.0-49-generic containerd://1.5.5 c1-node3 Ready worker 8h v1.22.4 172.22.17.203 <none> Ubuntu 21.04 5.11.0-49-generic containerd://1.5.5 k8s-c1-cp1 Ready control-plane,master 9h v1.22.4 172.22.17.200 <none> Ubuntu 21.04 5.11.0-49-generic containerd://1.5.5 root@k8s-c1-cp1:~#
Cluster üzerinde çalışan podların listesini alır. Eğer herhangi çalışan bir pod yok ise aşağıdaki şekilde çıktı verir.
root@k8s-c1-cp1:~# kubectl get pods No resources found in default namespace. root@k8s-c1-cp1:~#
Sistem bölümlerinin listesini almak ve namespace, kaynaklar ile birlikte gruplandırılmış halini gösterir,
root@k8s-c1-cp1:~# kubectl get pods --namespace kube-system NAME READY STATUS RESTARTS AGE calico-kube-controllers-6fd7b9848d-plnz5 1/1 Running 0 9h calico-node-9k9pm 1/1 Running 0 8h calico-node-gr575 1/1 Running 0 9h calico-node-tqtjx 1/1 Running 0 9h calico-node-zth86 1/1 Running 0 8h coredns-78fcd69978-v4cvf 1/1 Running 0 9h coredns-78fcd69978-xs8wg 1/1 Running 0 9h etcd-k8s-c1-cp1 1/1 Running 0 9h kube-apiserver-k8s-c1-cp1 1/1 Running 0 9h kube-controller-manager-k8s-c1-cp1 1/1 Running 0 9h kube-proxy-8lkgg 1/1 Running 0 8h kube-proxy-h5tz6 1/1 Running 0 9h kube-proxy-hngcb 1/1 Running 0 8h kube-proxy-zg89n 1/1 Running 0 9h kube-scheduler-k8s-c1-cp1 1/1 Running 0 9h root@k8s-c1-cp1:~#
Her pod hakkında detaylı bilgi almak için kullanılır,
root@k8s-c1-cp1:~# kubectl get pods --namespace kube-system -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES calico-kube-controllers-6fd7b9848d-plnz5 1/1 Running 0 9h 192.168.84.193 k8s-c1-cp1 <none> <none> calico-node-9k9pm 1/1 Running 0 8h 172.22.17.202 c1-node2 <none> <none> calico-node-gr575 1/1 Running 0 9h 172.22.17.201 c1-node1 <none> <none> calico-node-tqtjx 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> calico-node-zth86 1/1 Running 0 8h 172.22.17.203 c1-node3 <none> <none> coredns-78fcd69978-v4cvf 1/1 Running 0 9h 192.168.84.195 k8s-c1-cp1 <none> <none> coredns-78fcd69978-xs8wg 1/1 Running 0 9h 192.168.84.194 k8s-c1-cp1 <none> <none> etcd-k8s-c1-cp1 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> kube-apiserver-k8s-c1-cp1 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> kube-controller-manager-k8s-c1-cp1 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> kube-proxy-8lkgg 1/1 Running 0 8h 172.22.17.203 c1-node3 <none> <none> kube-proxy-h5tz6 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> kube-proxy-hngcb 1/1 Running 0 8h 172.22.17.202 c1-node2 <none> <none> kube-proxy-zg89n 1/1 Running 0 9h 172.22.17.201 c1-node1 <none> <none> kube-scheduler-k8s-c1-cp1 1/1 Running 0 9h 172.22.17.200 k8s-c1-cp1 <none> <none> root@k8s-c1-cp1:~#
Tüm namespace üzerinde çalışan her şeyin bilgisini almak için kullanılır. Podlara ek olarak servisler, daemonsetler, deploymentlar ve replicasetleri gösterir.
root@k8s-c1-cp1:~# kubectl get all --all-namespaces | more NAMESPACE NAME READY STATUS RESTARTS AGE kube-system pod/calico-kube-controllers-6fd7b9848d-plnz5 1/1 Running 0 9h kube-system pod/calico-node-9k9pm 1/1 Running 0 8h kube-system pod/calico-node-gr575 1/1 Running 0 9h kube-system pod/calico-node-tqtjx 1/1 Running 0 9h kube-system pod/calico-node-zth86 1/1 Running 0 8h kube-system pod/coredns-78fcd69978-v4cvf 1/1 Running 0 9h kube-system pod/coredns-78fcd69978-xs8wg 1/1 Running 0 9h kube-system pod/etcd-k8s-c1-cp1 1/1 Running 0 9h kube-system pod/kube-apiserver-k8s-c1-cp1 1/1 Running 0 9h kube-system pod/kube-controller-manager-k8s-c1-cp1 1/1 Running 0 9h kube-system pod/kube-proxy-8lkgg 1/1 Running 0 8h kube-system pod/kube-proxy-h5tz6 1/1 Running 0 9h kube-system pod/kube-proxy-hngcb 1/1 Running 0 8h kube-system pod/kube-proxy-zg89n 1/1 Running 0 9h kube-system pod/kube-scheduler-k8s-c1-cp1 1/1 Running 0 9h NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9h kube-system service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 9h NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE kube-system daemonset.apps/calico-node 4 4 4 4 4 kubernetes.io/os=linux 9h kube-system daemonset.apps/kube-proxy 4 4 4 4 4 kubernetes.io/os=linux 9h NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE kube-system deployment.apps/calico-kube-controllers 1/1 1 1 9h kube-system deployment.apps/coredns 2/2 2 2 9h NAMESPACE NAME DESIRED CURRENT READY AGE kube-system replicaset.apps/calico-kube-controllers-6fd7b9848d 1 1 1 9h kube-system replicaset.apps/coredns-78fcd69978 2 2 2 9h root@k8s-c1-cp1:~#
Kubernetesten bildiği kaynakları listeleme. Her sütundaki başlıkları inceleyerek, Name, Alias, API Version bilgilerini görme.
root@k8s-c1-cp1:~# kubectl api-resources | more NAME SHORTNAMES APIVERSION NAMESPACED KIND bindings v1 true Binding componentstatuses cs v1 false ComponentStatus configmaps cm v1 true ConfigMap endpoints ep v1 true Endpoints events ev v1 true Event limitranges limits v1 true LimitRange namespaces ns v1 false Namespace nodes no v1 false Node persistentvolumeclaims pvc v1 true PersistentVolumeClaim persistentvolumes pv v1 false PersistentVolume pods po v1 true Pod podtemplates v1 true PodTemplate replicationcontrollers rc v1 true ReplicationController resourcequotas quota v1 true ResourceQuota secrets v1 true Secret serviceaccounts sa v1 true ServiceAccount services svc v1 true Service mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition apiservices apiregistration.k8s.io/v1 false APIService controllerrevisions apps/v1 true ControllerRevision daemonsets ds apps/v1 true DaemonSet deployments deploy apps/v1 true Deployment replicasets rs apps/v1 true ReplicaSet statefulsets sts apps/v1 true StatefulSet tokenreviews authentication.k8s.io/v1 false TokenReview localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview horizontalpodautoscalers hpa autoscaling/v1 true HorizontalPodAutoscaler cronjobs cj batch/v1 true CronJob jobs batch/v1 true Job certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest leases coordination.k8s.io/v1 true Lease bgpconfigurations crd.projectcalico.org/v1 false BGPConfiguration bgppeers crd.projectcalico.org/v1 false BGPPeer blockaffinities crd.projectcalico.org/v1 false BlockAffinity caliconodestatuses crd.projectcalico.org/v1 false CalicoNodeStatus clusterinformations crd.projectcalico.org/v1 false ClusterInformation felixconfigurations crd.projectcalico.org/v1 false FelixConfiguration globalnetworkpolicies crd.projectcalico.org/v1 false GlobalNetworkPolicy globalnetworksets crd.projectcalico.org/v1 false GlobalNetworkSet hostendpoints crd.projectcalico.org/v1 false HostEndpoint ipamblocks crd.projectcalico.org/v1 false IPAMBlock ipamconfigs crd.projectcalico.org/v1 false IPAMConfig ipamhandles crd.projectcalico.org/v1 false IPAMHandle ippools crd.projectcalico.org/v1 false IPPool ipreservations crd.projectcalico.org/v1 false IPReservation kubecontrollersconfigurations crd.projectcalico.org/v1 false KubeControllersConfiguration networkpolicies crd.projectcalico.org/v1 true NetworkPolicy networksets crd.projectcalico.org/v1 true NetworkSet endpointslices discovery.k8s.io/v1 true EndpointSlice events ev events.k8s.io/v1 true Event flowschemas flowcontrol.apiserver.k8s.io/v1beta1 false FlowSchema prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta1 false PriorityLevelConfiguration ingressclasses networking.k8s.io/v1 false IngressClass ingresses ing networking.k8s.io/v1 true Ingress networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy runtimeclasses node.k8s.io/v1 false RuntimeClass poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding clusterroles rbac.authorization.k8s.io/v1 false ClusterRole rolebindings rbac.authorization.k8s.io/v1 true RoleBinding roles rbac.authorization.k8s.io/v1 true Role priorityclasses pc scheduling.k8s.io/v1 false PriorityClass csidrivers storage.k8s.io/v1 false CSIDriver csinodes storage.k8s.io/v1 false CSINode csistoragecapacities storage.k8s.io/v1beta1 true CSIStorageCapacity storageclasses sc storage.k8s.io/v1 false StorageClass volumeattachments storage.k8s.io/v1 false VolumeAttachment root@k8s-c1-cp1:~#
Filtreleme yaparak kolayca gruplarımızı listeleyebiliriz,
root@k8s-c1-cp1:~# kubectl api-resources | grep pod pods po v1 true Pod podtemplates v1 true PodTemplate horizontalpodautoscalers hpa autoscaling/v1 true HorizontalPodAutoscaler poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy root@k8s-c1-cp1:~#
Kaynağı ayrıntılı olarak açıklamalarını görmek için,
kubectl explain pod | more kubectl explain pod.spec | more kubectl explain pod.spec.containers | more kubectl explain pod --recursive | more
Tanım kullanarak nodalara daha yakından incelemek için ve Name, Taints, Conditions, Addresses, System INfo, Non-Terminated, Pods ve Events lar hakkında bilgi alabiliriz.
root@k8s-c1-cp1:~# kubectl describe nodes k8s-c1-cp1 | more Name: k8s-c1-cp1 Roles: control-plane,master Labels: beta.kubernetes.io/arch=amd64 beta.kubernetes.io/os=linux kubernetes.io/arch=amd64 kubernetes.io/hostname=k8s-c1-cp1 kubernetes.io/os=linux node-role.kubernetes.io/control-plane= node-role.kubernetes.io/master= node.kubernetes.io/exclude-from-external-load-balancers= Annotations: kubeadm.alpha.kubernetes.io/cri-socket: /run/containerd/containerd.sock node.alpha.kubernetes.io/ttl: 0 projectcalico.org/IPv4Address: 172.22.17.200/24 projectcalico.org/IPv4IPIPTunnelAddr: 192.168.84.192 volumes.kubernetes.io/controller-managed-attach-detach: true CreationTimestamp: Wed, 16 Mar 2022 08:23:09 +0000 Taints: node-role.kubernetes.io/master:NoSchedule Unschedulable: false Lease: HolderIdentity: k8s-c1-cp1 AcquireTime: <unset> RenewTime: Wed, 16 Mar 2022 18:24:07 +0000 Conditions: Type Status LastHeartbeatTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- NetworkUnavailable False Wed, 16 Mar 2022 08:26:47 +0000 Wed, 16 Mar 2022 08:26:47 +0000 CalicoIsUp Calico is running on this node MemoryPressure False Wed, 16 Mar 2022 18:22:55 +0000 Wed, 16 Mar 2022 08:23:05 +0000 KubeletHasSufficientMemory kubelet has sufficient memory available DiskPressure False Wed, 16 Mar 2022 18:22:55 +0000 Wed, 16 Mar 2022 08:23:05 +0000 KubeletHasNoDiskPressure kubelet has no disk pressure PIDPressure False Wed, 16 Mar 2022 18:22:55 +0000 Wed, 16 Mar 2022 08:23:05 +0000 KubeletHasSufficientPID kubelet has sufficient PID available Ready True Wed, 16 Mar 2022 18:22:55 +0000 Wed, 16 Mar 2022 08:26:39 +0000 KubeletReady kubelet is posting ready status. AppArmor enabled Addresses: InternalIP: 172.22.17.200 Hostname: k8s-c1-cp1 Capacity: cpu: 4 ephemeral-storage: 81529272Ki hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 16388396Ki pods: 110 Allocatable: cpu: 4 ephemeral-storage: 75137376951 hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 16285996Ki pods: 110 System Info: Machine ID: 500ab52583484b5eb60bd738405c4a3c System UUID: fdf30142-00d8-d8fc-73fb-8c15facbf0e5 Boot ID: bf113caf-f511-4d15-82c1-684e0ad19afb Kernel Version: 5.11.0-49-generic OS Image: Ubuntu 21.04 Operating System: linux Architecture: amd64 Container Runtime Version: containerd://1.5.5 Kubelet Version: v1.22.4 Kube-Proxy Version: v1.22.4 Non-terminated Pods: (9 in total) Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits Age --------- ---- ------------ ---------- --------------- ------------- --- kube-system calico-kube-controllers-6fd7b9848d-plnz5 0 (0%) 0 (0%) 0 (0%) 0 (0%) 9h kube-system calico-node-tqtjx 250m (6%) 0 (0%) 0 (0%) 0 (0%) 9h kube-system coredns-78fcd69978-v4cvf 100m (2%) 0 (0%) 70Mi (0%) 170Mi (1%) 10h kube-system coredns-78fcd69978-xs8wg 100m (2%) 0 (0%) 70Mi (0%) 170Mi (1%) 10h kube-system etcd-k8s-c1-cp1 100m (2%) 0 (0%) 100Mi (0%) 0 (0%) 10h kube-system kube-apiserver-k8s-c1-cp1 250m (6%) 0 (0%) 0 (0%) 0 (0%) 10h kube-system kube-controller-manager-k8s-c1-cp1 200m (5%) 0 (0%) 0 (0%) 0 (0%) 10h kube-system kube-proxy-h5tz6 0 (0%) 0 (0%) 0 (0%) 0 (0%) 10h kube-system kube-scheduler-k8s-c1-cp1 100m (2%) 0 (0%) 0 (0%) 0 (0%) 10h Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted.) Resource Requests Limits -------- -------- ------ cpu 1100m (27%) 0 (0%) memory 240Mi (1%) 340Mi (2%) ephemeral-storage 0 (0%) 0 (0%) hugepages-1Gi 0 (0%) 0 (0%) hugepages-2Mi 0 (0%) 0 (0%) Events: <none> root@k8s-c1-cp1:~#
Yardım almak için -h ve ya –help kullanın,
kubectl -h | more kubectl get -h | more kubectl create -h | more
Kubernetes clusterımız ve nodlarımız hakkında genel kullanımda kullanabileceğimiz komutlar bu şekilde sıralanabilir, ögrendikçe, payalşmaya devam..