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¶
IKS - Objects - Kube Basics
References¶
Prints all API Resources
oc api-resources
oc api-resources -o wide
oc api-resources -o name
oc get nodes,ns,po,deploy,svc
oc describe node
Getting API Resources
kubectl api-resources
kubectl api-resources -o wide
kubectl api-resources -o name
kubectl get nodes,ns,po,deploy,svc
kubectl describe node --all
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 - About Pods - Cluster Configuration for Pods - Pod Autoscaling
IKS - Pod Overview - Pod Lifecycle - Pod Usage
References¶
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
Get Current Pods in Project
oc get pods
oc describe pod <pod-name>
oc get pods -o wide
oc adm top pods
Get Current Pods in Project
kubectl get pods
kubectl describe pod <pod-name>
kubectl delete pod <pod-name>
kubectl edit pod <pod-name>
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 - Working With Projects - Creating Projects - Configure Project Creation
IKS - Namespaces
References:¶
apiVersion: v1
kind: Namespace
metadata:
name: foo
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
namespace: bar
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
Create a new Project
oc new-project my-project
Viewing Current Project
oc project
Viewing Project Status
oc status
Getting all namespaces in cluster
kubectl get namespaces
Create a new namespace called bar
kubectl create ns bar
kubectl set-context --current --namespace=bar