Kubernetes Core Concepts
Kubernetes API Primitives
Kubernetes API primitive, also known as Kubernetes objects, are the basic building blocks of any application running in Kubernetes
Examples:
- Pod
- Node
- Service
- ServiceAccount
Two primary members
- Spec, desired state
- Status, current state
Resources
OpenShift
IKS
References
Prints all API Resources
oc api-resources
Prints all API Resources with their verbs.
oc api-resources -o wide
Prints all API Resources names only
oc api-resources -o name
Explain the Resource specification
oc explain Pod.spec
Getting a list of specific objects
oc get nodes,ns,po,deploy,svc
Describing the resources
oc describe node
Prints all API Resources
kubectl api-resources
Prints all API Resources with their verbs.
kubectl api-resources -o wide
Prints all API Resources names only
kubectl api-resources -o name
Explain the Resource specification
kubectl explain Pod.spec
Getting a list of specific objects
kubectl get nodes,ns,po,deploy,svc
Describing the resources
kubectl describe node
Creating Pods
A Pod is the basic execution unit of a Kubernetes application–the smallest and simplest unit in the Kubernetes object model that you create or deploy. A Pod represents processes running on your Cluster.
A Pod encapsulates an application’s container (or, in some cases, multiple containers), storage resources, a unique network IP, and options that govern how the container(s) should run. A Pod represents a unit of deployment: a single instance of an application in Kubernetes, which might consist of either a single container or a small number of containers that are tightly coupled and that share resources.
Resources
OpenShift
IKS
References
apiVersion: v1kind: Podmetadata:name: myapp-podlabels:app: myappspec:containers:- name: myapp-container
Create Pod using yaml file
oc apply -f pod.yaml
Get Current Pods in Project
oc get pods
Get Pods with their IP and node location
oc get pods -o wide
Get Pod’s Description
oc describe pod myapp-pod
Get the logs
oc logs myapp-pod
Delete a Pod
oc delete pod myapp-pod
Create Pod using yaml file
kubectl apply -f pod.yaml
Get Current Pods in Project
kubectl get pods
Get Pods with their IP and node location
kubectl get pods -o wide
Get Pod’s Description
kubectl describe pod myapp-pod
Get the logs
kubectl logs myapp-pod
Delete a Pod
kubectl delete pod myapp-pod
Projects/Namespaces
Namespaces are intended for use in environments with many users spread across multiple teams, or projects.
Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces.
Namespaces are a way to divide cluster resources between multiple users (via resource quota).
It is not necessary to use multiple namespaces just to separate slightly different resources, such as different versions of the same software: use labels to distinguish resources within the same namespace. In practice namespaces are used to deploy different versions based on stages of the CICD pipeline (dev, test, stage, prod)
Resources
OpenShift
IKS
References:
apiVersion: v1kind: Namespacemetadata:name: dev
apiVersion: v1kind: Podmetadata:name: myapp-podnamespace: devspec:containers:- name: myapp-containerimage: busybox
Getting all namespaces/projects
oc projects
Create a new Project
oc new-project dev
Viewing Current Project
oc project
Setting Namespace in Context
oc project dev
Viewing Project Status
oc status
Getting all namespaces
kubectl get namespaces
Create a new namespace called bar
kubectl create ns dev
Setting Namespace in Context
kubectl config set-context --current --namespace=dev