Table of Contents
Kubernetes
Create new Kubernetes project
mkdir k8s_project
cd k8s_project
Config file for creating cluster
e.g. It contains one master and two worker/slave node.
vim clusters.yml
-----------------------------------
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
-----------------------------------
Command to create a cluster named ‘local’
kind create cluster --config clusters.yml --name local
Verification of new nodes created on kubernetes
(base) k8s_project % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96ba7abb765d kindest/node:v1.32.0 "/usr/local/bin/entr…" 22 hours ago Up 22 hours local-worker
127832dd8ea6 kindest/node:v1.32.0 "/usr/local/bin/entr…" 22 hours ago Up 22 hours local-worker2
e35eff14a268 kindest/node:v1.32.0 "/usr/local/bin/entr…" 22 hours ago Up 22 hours 127.0.0.1:52118->6443/tcp local-control-plane
Install kubectl
Option-1 to install kubectl
brew install kubectl
Option-2 to install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"\n
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256"\n
echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check\n
chmod +x ./kubectl\n
sudo mv ./kubectl /usr/local/bin/kubectl
sudo chown root: /usr/local/bin/kubectl
echo $PATH
Check all the nodes / machines present in kubernetes cluster
This will fire the http api request to api server for getting the information.
(base) k8s_project % kubectl get nodes
NAME STATUS ROLES AGE VERSION
local-control-plane Ready control-plane 21h v1.32.0
local-worker Ready <none> 21h v1.32.0
local-worker2 Ready <none> 21h v1.32.0
Verbose output level 8
(base) k8s_project % kubectl get nodes --v=8
I0105 11:34:15.115262 81573 loader.go:402] Config loaded from file: /Users/Admin/.kube/config
I0105 11:34:15.115774 81573 envvar.go:172] "Feature gate default state" feature="ClientsAllowCBOR" enabled=false
I0105 11:34:15.115782 81573 envvar.go:172] "Feature gate default state" feature="ClientsPreferCBOR" enabled=false
I0105 11:34:15.115784 81573 envvar.go:172] "Feature gate default state" feature="InformerResourceVersion" enabled=false
I0105 11:34:15.115787 81573 envvar.go:172] "Feature gate default state" feature="WatchListClient" enabled=false
I0105 11:34:15.115979 81573 discovery_client.go:253] "Request Body" body=""
I0105 11:34:15.116093 81573 round_trippers.go:470] GET https://127.0.0.1:52118/api?timeout=32s
I0105 11:34:15.116097 81573 round_trippers.go:476] Request Headers:
I0105 11:34:15.116100 81573 round_trippers.go:480] Accept: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList,application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
I0105 11:34:15.116102 81573 round_trippers.go:480] User-Agent: kubectl/v1.32.0 (darwin/arm64) kubernetes/70d3cc9
I0105 11:34:15.124851 81573 round_trippers.go:581] Response Status: 200 OK in 8 milliseconds
I0105 11:34:15.124861 81573 round_trippers.go:584] Response Headers:
I0105 11:34:15.124865 81573 round_trippers.go:587] Audit-Id: f37feb10-f53c-4481-a81e-9c1c92fa5889
I0105 11:34:15.124868 81573 round_trippers.go:587] Content-Type: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList
I0105 11:34:15.124870 81573 round_trippers.go:587] Date: Sun, 05 Jan 2025 06:04:15 GMT
I0105 11:34:15.124872 81573 round_trippers.go:587] X-Kubernetes-Pf-Flowschema-Uid: 4c2be9d9-b0e6-47e8-8ab6-29d1a46eb75d
I0105 11:34:15.124874 81573 round_trippers.go:587] X-Varied-Accept: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList,application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
I0105 11:34:15.124876 81573 round_trippers.go:587] X-From-Cache: 1
I0105 11:34:15.124877 81573 round_trippers.go:587] Cache-Control: public
I0105 11:34:15.124878 81573 round_trippers.go:587] Etag: "7E2E4FBD8CDC884130EBFEF64757F6BC507A8EA6A2EA8F94E05F1B6F207B4E183C63D6D6EA5513FDDC10FC16233248F933DC787C288493D52745A3FAFD68CCD8"
I0105 11:34:15.124879 81573 round_trippers.go:587] Vary: Accept
I0105 11:34:15.124881 81573 round_trippers.go:587] X-Kubernetes-Pf-Prioritylevel-Uid: 74f7cf31-7a5d-4c93-adf6-1efd49db0d1b
I0105 11:34:15.125977 81573 discovery_client.go:253] "Response Body" body="{\"kind\":\"APIGroupDiscoveryList\",\"apiVersion\":\"apidiscovery.k8s.io/v2\",\"metadata\":{},\"items\":[{\"metadata\":{\"creationTimestamp\":null},\"versions\":[{\"version\":\"v1\",\"resources\":[{\"resource\":\"bindings\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"Binding\"},\"scope\":\"Namespaced\",\"singularResource\":\"binding\",\"verbs\":[\"create\"]},{\"resource\":\"componentstatuses\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"ComponentStatus\"},\"scope\":\"Cluster\",\"singularResource\":\"componentstatus\",\"verbs\":[\"get\",\"list\"],\"shortNames\":[\"cs\"]},{\"resource\":\"configmaps\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"ConfigMap\"},\"scope\":\"Namespaced\",\"singularResource\":\"configmap\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"],\"shortNames\":[\"cm\"]},{\"resource\":\"endpoints\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"Endpoints\"},\"scope\":\"Namespaced\",\"singularResource\":\"endpoints\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"],\"shortNames\":[\"ep\"]},{\"resource\":\"event [truncated 5940 chars]"
I0105 11:34:15.126597 81573 discovery_client.go:319] "Request Body" body=""
I0105 11:34:15.126618 81573 round_trippers.go:470] GET https://127.0.0.1:52118/apis?timeout=32s
I0105 11:34:15.126622 81573 round_trippers.go:476] Request Headers:
I0105 11:34:15.126625 81573 round_trippers.go:480] Accept: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList,application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
I0105 11:34:15.126627 81573 round_trippers.go:480] User-Agent: kubectl/v1.32.0 (darwin/arm64) kubernetes/70d3cc9
I0105 11:34:15.128343 81573 round_trippers.go:581] Response Status: 200 OK in 1 milliseconds
I0105 11:34:15.128349 81573 round_trippers.go:584] Response Headers:
I0105 11:34:15.128353 81573 round_trippers.go:587] Vary: Accept
I0105 11:34:15.128355 81573 round_trippers.go:587] X-Kubernetes-Pf-Flowschema-Uid: 4c2be9d9-b0e6-47e8-8ab6-29d1a46eb75d
I0105 11:34:15.128356 81573 round_trippers.go:587] X-Varied-Accept: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList,application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
I0105 11:34:15.128358 81573 round_trippers.go:587] X-Kubernetes-Pf-Prioritylevel-Uid: 74f7cf31-7a5d-4c93-adf6-1efd49db0d1b
I0105 11:34:15.128360 81573 round_trippers.go:587] X-From-Cache: 1
I0105 11:34:15.128362 81573 round_trippers.go:587] Audit-Id: 15094361-7683-4f46-bd89-73f70d2ae09f
I0105 11:34:15.128364 81573 round_trippers.go:587] Cache-Control: public
I0105 11:34:15.128365 81573 round_trippers.go:587] Content-Type: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList
I0105 11:34:15.128366 81573 round_trippers.go:587] Date: Sun, 05 Jan 2025 06:04:15 GMT
I0105 11:34:15.128368 81573 round_trippers.go:587] Etag: "366E26A714A41183C0C71F8F88DC1CAEF07F3F125C2DA4E1408F6D6EB13A931F135F6316619C287FAD20670F043F62D50C55052CE5F976CDE2363579DC014CA9"
I0105 11:34:15.129084 81573 discovery_client.go:319] "Response Body" body="{\"kind\":\"APIGroupDiscoveryList\",\"apiVersion\":\"apidiscovery.k8s.io/v2\",\"metadata\":{},\"items\":[{\"metadata\":{\"name\":\"apiregistration.k8s.io\",\"creationTimestamp\":null},\"versions\":[{\"version\":\"v1\",\"resources\":[{\"resource\":\"apiservices\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"APIService\"},\"scope\":\"Cluster\",\"singularResource\":\"apiservice\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"],\"categories\":[\"api-extensions\"],\"subresources\":[{\"subresource\":\"status\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"APIService\"},\"verbs\":[\"get\",\"patch\",\"update\"]}]}],\"freshness\":\"Current\"}]},{\"metadata\":{\"name\":\"apps\",\"creationTimestamp\":null},\"versions\":[{\"version\":\"v1\",\"resources\":[{\"resource\":\"controllerrevisions\",\"responseKind\":{\"group\":\"\",\"version\":\"\",\"kind\":\"ControllerRevision\"},\"scope\":\"Namespaced\",\"singularResource\":\"controllerrevision\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"]},{\"resource\":\"daemonsets\",\"responseKind\":{\"group\":\"\",\"versi [truncated 14950 chars]"
I0105 11:34:15.136337 81573 helper.go:113] "Request Body" body=""
I0105 11:34:15.136358 81573 round_trippers.go:470] GET https://127.0.0.1:52118/api/v1/nodes?limit=500
I0105 11:34:15.136361 81573 round_trippers.go:476] Request Headers:
I0105 11:34:15.136365 81573 round_trippers.go:480] Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json
I0105 11:34:15.136368 81573 round_trippers.go:480] User-Agent: kubectl/v1.32.0 (darwin/arm64) kubernetes/70d3cc9
I0105 11:34:15.139677 81573 round_trippers.go:581] Response Status: 200 OK in 3 milliseconds
I0105 11:34:15.139683 81573 round_trippers.go:584] Response Headers:
I0105 11:34:15.139687 81573 round_trippers.go:587] Audit-Id: 471af011-8134-4fa4-bd9f-ac58dc7e298e
I0105 11:34:15.139690 81573 round_trippers.go:587] Cache-Control: no-cache, private
I0105 11:34:15.139691 81573 round_trippers.go:587] Content-Type: application/json
I0105 11:34:15.139692 81573 round_trippers.go:587] X-Kubernetes-Pf-Flowschema-Uid: 4c2be9d9-b0e6-47e8-8ab6-29d1a46eb75d
I0105 11:34:15.139694 81573 round_trippers.go:587] X-Kubernetes-Pf-Prioritylevel-Uid: 74f7cf31-7a5d-4c93-adf6-1efd49db0d1b
I0105 11:34:15.139695 81573 round_trippers.go:587] Date: Sun, 05 Jan 2025 06:04:15 GMT
I0105 11:34:15.139766 81573 helper.go:113] "Response Body" body="{\"kind\":\"Table\",\"apiVersion\":\"meta.k8s.io/v1\",\"metadata\":{\"resourceVersion\":\"12013\"},\"columnDefinitions\":[{\"name\":\"Name\",\"type\":\"string\",\"format\":\"name\",\"description\":\"Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names\",\"priority\":0},{\"name\":\"Status\",\"type\":\"string\",\"format\":\"\",\"description\":\"The status of the node\",\"priority\":0},{\"name\":\"Roles\",\"type\":\"string\",\"format\":\"\",\"description\":\"The roles of the node\",\"priority\":0},{\"name\":\"Age\",\"type\":\"string\",\"format\":\"\",\"description\":\"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is rep [truncated 9116 chars]"
NAME STATUS ROLES AGE VERSION
local-control-plane Ready control-plane 21h v1.32.0
local-worker Ready <none> 21h v1.32.0
local-worker2 Ready <none> 21h v1.32.0
Create new pods
(base) k8s_project % kubectl run nginxpod --image=nginx --port=80
pod/nginxpod created
(base) k8s_project % kubectl get pod
NAME READY STATUS RESTARTS AGE
nginxpod 0/1 ContainerCreating 0 6s
(base) k8s_project % kubectl get pod
NAME READY STATUS RESTARTS AGE
nginxpod 0/1 ErrImagePull 0 11s
Solution : User different image registry
# kubectl delete pod nginxpod
# kubectl run nginxpod --image=docker.io/library/nginx:1.25.0 --port=80
pod/nginxpod created
# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginxpod 1/1 Running 0 58s
Leave a Reply