Docker
K8s yml

Kubernetes YML

Kubectl Apply

#create/update resources in a file
kubectl apply -f myfile.yaml
 
#create/update aa whole directory of yaml
kubectl apply -f myyaml/
 
#create/update from a URL
kubectl apply -f https://hamid.run/pod.yml
 
#be careful. lets look at it first (brower or curl)
curl -L https://hamid.run/pod
 

Building your YAML Files

kind: We can get a list of resources the cluster supports

kubectl api-resources

Notice some resources have multiple API’s (old vs. new)

apiVersion: We can get the API versions the cluster supports

kubectl api-versions

metadata: only name is required

specs: Where all action is at

docs through command for specs

we can get all the keys each kind supports

kubectl explain service --recursive

if we need to only about spec

kubectl explain service.spec

spec: can have sub spec: of other resources

kubectl explain deployment.spec.template.spec.volumes.nfs.server

website docs

https://kubernetes.io/docs/home/supported-doc-versions/ (opens in a new tab)


Label and Label Selector

Labels: In Kubernetes, labels are key-value pairs attached to resources like Pods, Deployments, and Services. They provide metadata to categorize and identify resources. For example:

metadata:
  labels:
    app: backend
    env: production

Label Selectors: Label selectors are used to select resources based on their labels. There are three types:

  1. Equality-Based Selectors:
spec:
  selector:
    matchLabels:
      app: backend

Selects resources with the label "app" set to "backend".

  1. Set-Based Selectors:
spec:
  selector:
    matchExpressions:
      - { key: env, operator: In, values: [staging, production] }

Selects resources with the label "env" having a value of either "staging" or "production".

  1. Existence-Based Selectors:
spec:
  selector:
    matchExpressions:
      - { key: tier, operator: DoesNotExist }

Selects resources where the label "tier" does not exist.

Label selectors help in grouping resources based on specific criteria, enabling efficient management and interaction with Kubernetes objects.