containers

Working With Services

Kubernetes Services Here are more notes while learning Kubernetes, now it is about Services: Imperative Way Given the following manifest for a Deployment: ❯ cat deploy.yml apiVersion: apps/v1 kind: Deployment <<<====== metadata: name: svc-test <<<<===== spec: replicas: 10 selector: matchLabels: chapter: services template: metadata: labels: chapter: services spec: containers: - name: hello-ctr image: nigelpoulton/k8sbook:1.0 ports: - containerPort: 8080 First, we will create this one in a declarative way: ❯ kubectl apply -f deploy.

Working With Deployments(2)

Creating a Service to Access the Pod Tried to create the Service with the YAML manifest from the book but it seems that the port is not valid for today’s Kubernetes version: ❯ kubectl apply -f svc.yml The Service "hello-svc" is invalid: spec.ports[0].nodePort: Invalid value: 30001: provided port is not in the valid range. The range of valid ports is 32768-35535 So, I used a different port from the valid range mentioned in the previous output and the Service was created: ❯ kubectl apply -f svc.

Working With Deployments

Creating a Deployment ❯ kubectl apply -f deploy.yml deployment.apps/hello-deploy created ❯ kubectl get deployment NAME READY UP-TO-DATE AVAILABLE AGE hello-deploy 10/10 10 6 16s NOTE: I am following Nigel Poulton’s book examples. The “deploy.yml” YAML manifest can be found in the following repo: TheK8sBook Inspecting a Deployment ❯ kubectl describe deployment hello-deploy Name: hello-deploy Namespace: default CreationTimestamp: Wed, 16 Mar 2022 17:50:04 +0100 Labels: <none> Annotations: deployment.kubernetes.io/revision: 1 Selector: app=hello-world Replicas: 10 desired | 10 updated | 10 total | 10 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 10 RollingUpdateStrategy: 1 max unavailable, 1 max surge Pod Template: Labels: app=hello-world Containers: hello-pod: Image: nigelpoulton/k8sbook:1.

Kubernetes Multicontainer Pod

1- Init Container Pattern In a nutshell, the initcontainer must succesfully complete so the rest of containers can start. See example below: Given the following manifest: ❯ cat initpod.yml apiVersion: v1 kind: Pod metadata: name: initpod labels: app: initializer spec: initContainers: - name: init-ctr image: busybox command: ['sh', '-c', 'until nslookup k8sbook; do echo waiting for k8sbook service; sleep 1; done; echo Service found!'] containers: - name: web-ctr image: nigelpoulton/web-app:1.0 ports: - containerPort: 8080 The pod is created but it will not move forward creating the "

Working With Pods

Here are some notes and few tests while going through the book “The Kubernetes Book” from Nigel Poulton. Checking Kubernetes Nodes ❯ kubectl get nodes NAME STATUS ROLES AGE VERSION mke-manager-0 Ready master 27d v1.20.11-mirantis-1 mke-manager-1 Ready master 27d v1.20.11-mirantis-1 mke-manager-2 Ready master 27d v1.20.11-mirantis-1 mke-node-0 Ready <none> 27d v1.20.11-mirantis-1 mke-node-1 Ready <none> 27d v1.20.11-mirantis-1 Defining Manifest apiVersion: v1 kind: Pod metadata: name: hello-pod labels: name: v1 spec: containers: - name: hello-ctr image: nigelpoulton/k8sbook:1.