Workloads Link to heading

https://kubernetes.io/docs/concepts/workloads/

All the different ways we have to run applications in kubernetes. The workloads.

These are:

  • Pods
  • Deployments
  • ReplicatSet
  • StatefulSet
  • DaemonSet
  • Jobs
  • CronJobs

Pod Link to heading

These are ephimeral objects. Once stopped the storage is gone, the ip address is gone.

The different phase of a pod lifecycle are: Pending, Running, Succeeded, Failed and Unknown.

Also the container lifecycle phases: Waiting, Running, Terminated.

Here we can see all the Pod spec fields available:

~z➤ kubectl explain pod.spec | ag '^\s{2}[a-zA-Z].*'
  activeDeadlineSeconds <integer>
  affinity      <Affinity>
  automountServiceAccountToken  <boolean>
  containers    <[]Container> -required-
  dnsConfig     <PodDNSConfig>
  dnsPolicy     <string>
  enableServiceLinks    <boolean>
  ephemeralContainers   <[]EphemeralContainer>
  hostAliases   <[]HostAlias>
  hostIPC       <boolean>
  hostNetwork   <boolean>
  hostPID       <boolean>
  hostUsers     <boolean>
  hostname      <string>
  imagePullSecrets      <[]LocalObjectReference>
  initContainers        <[]Container>
  nodeName      <string>
  nodeSelector  <map[string]string>
  os    <PodOS>
  overhead      <map[string]Quantity>
  preemptionPolicy      <string>
  priority      <integer>
  priorityClassName     <string>
  readinessGates        <[]PodReadinessGate>
  resourceClaims        <[]PodResourceClaim>
  restartPolicy <string>
  runtimeClassName      <string>
  schedulerName <string>
  schedulingGates       <[]PodSchedulingGate>
  securityContext       <PodSecurityContext>
  serviceAccount        <string>
  serviceAccountName    <string>
  setHostnameAsFQDN     <boolean>
  shareProcessNamespace <boolean>
  subdomain     <string>
  terminationGracePeriodSeconds <integer>
  tolerations   <[]Toleration>
  topologySpreadConstraints     <[]TopologySpreadConstraint>
  volumes       <[]Volume>

Lab01 Link to heading

So if you run this lab k apply -f 02.lab01.yaml. You will get your Pod running with two containers, take a look into the 🔗 manifests/02.lab01.yaml file.

Now let’s see how Pod is running and containers initialized.

~z➤ k get pods
NAME                              READY   STATUS    RESTARTS   AGE
example-pod-with-init-container   1/1     Running   0          3m17s

~z➤ k logs example-pod-with-init-container -c init-myservice
We are fetching some configs for app-container!

~z➤ k logs example-pod-with-init-container -c app-container
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/12/30 03:01:46 [notice] 1#1: using the "epoll" event method
2023/12/30 03:01:46 [notice] 1#1: nginx/1.25.3
2023/12/30 03:01:46 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2023/12/30 03:01:46 [notice] 1#1: OS: Linux 5.10.57
2023/12/30 03:01:46 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/12/30 03:01:46 [notice] 1#1: start worker processes
2023/12/30 03:01:46 [notice] 1#1: start worker process 29
2023/12/30 03:01:46 [notice] 1#1: start worker process 30

You will realize only the app container is running at the end, the init container run only once and finished:

~z➤ k exec -it example-pod-with-init-container -c init-myservice -- uname -a
error: unable to upgrade connection: container not found ("init-myservice")

~z➤ k exec -it example-pod-with-init-container -c app-container -- uname -a
Linux example-pod-with-init-container 5.10.57 #1 SMP Tue Nov 7 06:51:54 UTC 2023 x86_64 GNU/Linux

👀 NOTE: A shell remote execution via kubectl is done via HTTPS (not SSH) and using websockets through kubernetes API.