Skip to content

Commit 72ca53e

Browse files
committed
gateway api
1 parent 038be04 commit 72ca53e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

kubernetes/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Table of Contents:
2727
- [3.10. Ingress](#310-ingress)
2828
- [3.11. ConfigMap](#311-configmap)
2929
- [3.12. Liveness and Readiness](#312-liveness-and-readiness)
30+
- [3.13. Gateway](#313-gateway)
3031
- [4. Security](#4-security)
3132
- [4.1. Kubernetes API Server Control access](#41-kubernetes-api-server-control-access)
3233
- [4.2. Secure Pod and Container](#42-secure-pod-and-container)
@@ -70,6 +71,7 @@ Table of Contents:
7071
- Read and store the configuration
7172
- Command line interface
7273
- `kube-api-server`: exposes the Kubernetes API.
74+
7375
- The API is the front end for the Kubernetes control plane.
7476
- Kubernetes system components communicate only with the API server. API server is the only component that communicates with etcd.
7577
- Flow:
@@ -79,6 +81,7 @@ Table of Contents:
7981
```
8082

8183
- `etcd`: Consistent and highly-available key-value store used as Kubernetes's backing store for all cluster data.
84+
8285
- Explore the Kubernetes configuration and status in etcd:
8386

8487
```bash
@@ -212,6 +215,7 @@ kubectl get ev --field-selector type=Warning
212215
| Declarative object configuration | Directories of files | Production projects | 1+ | Highest |
213216

214217
- **Imperative commands**:
218+
215219
- User operates directly on live objects in a cluster.
216220
- The recommended way to get started or to run a one-off task in a cluster.
217221
- Example:
@@ -230,6 +234,7 @@ kubectl get ev --field-selector type=Warning
230234
- Commands do not provide a template for creating new objects.
231235

232236
- **Imperative object configuration**:
237+
233238
- `kubectl` command specifies the operation (create, replace, etc.), optional flags and at least one file name.
234239
- Example:
235240

@@ -253,6 +258,7 @@ kubectl get ev --field-selector type=Warning
253258
- Updates to live objects must be reflected in configuration files, or they will be lost during the next replacement.
254259

255260
- **Declarative object configuration**:
261+
256262
- User operates on object configuration files stored locally, however the user doesn't define the operations to be taken on the files. Create, update, and delete operations are automatically detected per-object by `kubectl`. This enables working on directories, where different operations might be needed for different objects.
257263
- Example:
258264

@@ -291,6 +297,7 @@ kubectl get ev --field-selector type=Warning
291297
- Each pods gets its own unique IP address and can communicate with all other pods through a flat, NAT-less network.
292298
- The network is set up by the system administrator or by a Container Network Interface (CNI) plugin, not by Kubernetes itself.
293299
- For example, CNI Flannel:
300+
294301
- Read more [here](https://chunqi.li/2015/10/10/Flannel-for-Docker-Overlay-Network/)
295302
- Network communicate - multihost.
296303
- Flannel also uses etcd to configure the settings and store the status.
@@ -416,26 +423,32 @@ spec:
416423
```
417424

418425
- Headless Service:
426+
419427
- Sometimes you don't need load-balancing and a single Service IP. In this case, you can create what are termed _headless service_, by explicitly specifying `"None"` for the cluster IP address (`.spec.clusterIP`).
420428
- For headless Services, a cluster IP is not allocated. kube-proxy does not handle these Services, and there is no load balancing or proxying done by the platform for them. The cluster DNS returns not just a single `A` record pointing to the service's cluster IP, but multiple `A` records, one for each pod that's part of the service. Clients can there fore query the DNS to get the IPs of all the pods in the service.
421429
- A headless Service allows a client to connect to whichever Pod it prefers, directly.
422430

423431
![](./imgs/headless_service.png)
424432

425433
- Expose services externally:
434+
426435
- ClusterIP services are only accessible within the cluster.
427436
- If you need to make a service available to the outside world, you can do one of the following:
437+
428438
- ~Assign an additional IP to a node and set it as one of the service's `externalIP`~.
429439
- Set the service's type to `NodePort` and access the service through the node's port(s).
440+
430441
- Kubernetes makes the service avaiable on a network port on all cluster nodes. Because the port is open on the nodes, it's called a node port.
431442
- Expose pods through a NodePort service:
432443

433444
![](./imgs/nodeport1.png)
445+
434446
- Expose multiple ports through with a NodePort service:
435447

436448
![](./imgs/nodeport2.png)
437449

438450
- Ask Kubernetes to provision a LoadBalancer by setting the type to `LoadBalancer`.
451+
439452
- The LoadBalancer stands in front of the nodes and handles the connections coming from the clients. It routes each connection to the service by forwarding it to the node port on one of the nodes.
440453
- The `LoadBalancer` service type is an extenstion of the `NodePort` type, which makes the service accessible through these node ports.
441454
- Expose a LoadBalancer service.
@@ -504,13 +517,15 @@ spec:
504517
- downwardAPI
505518
- A **PersistentVolume** object represents a storage volume available in the clsuter that can be used to persist application data.
506519
- A pod transitively references a persistent volume and its underlying storage by referring to a **PersistentVolumeClaim** object that references the **PersistentVolume** object, which then references the underlying storage. This allows the ownership of the persistent volume to be decoupled from the lifecyle of the pod.
520+
507521
- A **PersistentVolumeClaim** represents a user's claim on the persistent volume.
508522

509523
![](https://wangwei1237.github.io/Kubernetes-in-Action-Second-Edition/images/8.4.png)
510524

511525
- Benefits of using persistent volumes and claims:
512526
- The infrastructure-specific details are now decoupled from the application represents by the pod.
513527
- Example:
528+
514529
- Create PersistentVolume:
515530

516531
```yaml
@@ -612,6 +627,7 @@ volumeBindingMode: WaitForFirstConsumer # How volumes of this class are provisio
612627
- As a file in a pod (via volumes).
613628
- External image to pull secrets.
614629
- Generate secrets:
630+
615631
- Using files.
616632

617633
```bash
@@ -640,7 +656,9 @@ volumeBindingMode: WaitForFirstConsumer # How volumes of this class are provisio
640656
```
641657

642658
- Kubernetes Secrets are, by default, stored unencrypted in the API server's underlying data store (etcd). Anyone with API access can retrieve or modify a Secret, and so can anyone with access to etcd. Additionally, anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace; this includes indirect access such as the ability to create a Deployment.
659+
643660
- [Enable Encryption at Rest](https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/) for Secrest.
661+
644662
- Generate encryption keys: Create strong encryption keys using a secure method. Algorithms like AES-GCM are recommended for both confidentiality and integrity.
645663

646664
```shell
@@ -709,9 +727,11 @@ kubectl apply -f ns-test2.yaml
709727
```
710728

711729
- Understanding the (lack of) isolation between namespaces:
730+
712731
- When two pods created in different namespaces are scheduled to the same cluster node, they both run in the same OS kernel -> an application that break out of its container or consumes too much of the node's resources can ffect the operation of the other application.
713732

714733
![](https://wangwei1237.github.io/Kubernetes-in-Action-Second-Edition/images/10.3.png)
734+
715735
- Kubernetes doesn't provide network isolation between applications running in pods in different namespaces (by default) -> Can use the NetworkPolicy object to configure which applications in which namespaces can connect to which applications in other namespaces.
716736
- Should not use namespaces to split a single physical cluster into production, staging, and development environments.
717737

@@ -833,6 +853,19 @@ spec:
833853
- The kubelet uses startup probes to know when a container application has started. If such a probe is configured, it disables liveness and readiness checks until it succeeds, making sure those probes don't interfere with the application startup. This can be used to adopt liveness checks on slow stasrting containers, avoiding them getting killed by the kubelet before they are up and running.
834854
- Check [RedHat's blog](https://developers.redhat.com/blog/2020/11/10/you-probably-need-liveness-and-readiness-probes#example_2__a_jobs_server__no_rest_api_)
835855

856+
### 3.13. Gateway
857+
858+
- The [Gateway API](https://gateway-api.sigs.k8s.io/) is an official Kubernetes project, representing the next generation of APIs for ingress, load balancing and potentially even service mesh interactions. It provides a unified specification for configuring network traffic routing, aiming to be expressive, extensible and aligned with the different roles involved in managing Kubernetes infrastructure and applications.
859+
- The limitations of Ingress:
860+
- Kubernetes Ingress defines rules for exposing HTTP and HTTPS services running within the cluster to external clients. It typically relies on an Ingress controller, a separate piece of software running in the cluster that watches Ingress resources and configures an underlying load balancer or proxy accordingly. While simple path and host-based routing work well with Ingress, its core specification is limited (header-based routing, traffic splitting for canary releases, ...).
861+
- The single Ingress resource often blurs the lines of responsibility between infrastructure operators and application developers, potentially leading to configuration conflicts or overly broad permissions.
862+
- Resource model:
863+
- The primary resources are GatewayClass (cluster-scoped), Gateway, and various Route types (HTTPRoute, TCPRoute or GRPCRoute).
864+
- GatewayClass manages Gateways of this class.
865+
- Gateway requests a specific traffic entrypoint, like a load balancer IP address, based on a GatewayClass.
866+
- Route resources contain the specific rules for how traffic arriving at a Gateway listener should be mapped to backend Kubernetes services.
867+
- This layered approach allows platform team to manage the underlying infrastructure (GatewayClass, Gateway) and set policies. In contrast, application teams can independently manage the routing logic specific to their services (Route resources) within the established boundaries.
868+
836869
## 4. Security
837870

838871
### 4.1. Kubernetes API Server Control access
@@ -851,6 +884,7 @@ spec:
851884
- _system:serviceaccounts_: all ServiceAccounts in the system.
852885
- _system:serviceaccounts:\<namespace\>_: includes all ServiceAccounts in a specific namespace.
853886
- ServiceAccounts:
887+
854888
- Every Pod is associated with a ServiceAccount, which represents the identity of the app running in the pod.
855889
- Token file: `/var/run/secrets/kubernetes.io/serviceaccount/token`.
856890
- ServiceAccount's username: _system:serviceaccount:\<namespace\>:\<service account name\>_
@@ -868,6 +902,7 @@ spec:
868902
- Use ServiceAccount to enforce mountable Secrets or to provide image pull Secrets through the ServiceAccount.
869903

870904
- Authorization plugin - Role-based access control:
905+
871906
- Use user roles as the key factor in determining whether the user may perform the action or not. A subject is associated with one or more roles and each role is allowed to perform certain verbs on certain resources.
872907
- RBAC authorization rules are configured through 4 resources, which can be grouped into 2 groups:
873908
- **Role** and **ClusterRoles**, which specify which verbs can be performed on which resources.
@@ -876,6 +911,7 @@ spec:
876911
- RoleBindings and Roles are namespaced; ClusterRoles and ClusterRoleBindings aren't.
877912

878913
![](https://kublr.com/wp-content/uploads/2020/08/Screen-Shot-2020-08-13-at-10.58.16-AM.png)
914+
879915
- Create **Role**.
880916

881917
```yaml
@@ -942,11 +978,13 @@ kubectl exec pod-with-host-network ifconfig
942978
```
943979

944980
- Binding to a host port without using the host's network namespace.
981+
945982
- **NodePort** vs **hostPort**: **hostPort** a connection to the node's port is forwarded directly to the pod running on that node, whereas with a Nodeport service, a connection to the node's port is forwarded to a randomly selected pod.
946983

947984
![](https://t1.daumcdn.net/cfile/tistory/99F6953F5F1FB6001A)
948985

949986
![](https://t1.daumcdn.net/cfile/tistory/999DA53E5F1FB61E1A)
987+
950988
- Only one instance of the pod can be scheduled to each node.
951989

952990
- Container's security context.
@@ -974,8 +1012,10 @@ spec:
9741012
```
9751013
9761014
- Security-related features in pods:
1015+
9771016
- **PodSecurityPolicy** is a cluster-level resource, which defines what security-related features users can or can't use in their pods.
9781017
- **PodSecurityPolicy** resource defines things:
1018+
9791019
- Whether a pod can use the host's IPC, PID, or Network namespaces.
9801020
- Which host ports a pod can bind to.
9811021
- What user IDs a container can run as.
@@ -998,6 +1038,7 @@ spec:
9981038
```
9991039

10001040
- Isolate the pod network:
1041+
10011042
- How the network between pods can be secured by limiting which pods can talk to which pods -> depends on which container networking plugin is used in the cluster -> If plugin supports it, configure network isolation with **NetworkPolicy** resources.
10021043

10031044
- Deny all:
@@ -1056,6 +1097,7 @@ Source:
10561097
![](https://learnk8s.io/a/92543837cbecdd1189ee0a6d68fa9434.svg)
10571098

10581099
- Connecting Deployment and Service:
1100+
10591101
- The Service selector should match at least one Pod's label
10601102
- The Service's `targetPort` should match the `containerPort` of the Pod
10611103
- The Service `port` can by any number. Multiple Services can use the same port because they have different IP addresses assigned.
@@ -1108,6 +1150,7 @@ Source:
11081150
```
11091151

11101152
- Connecting Service and Ingress:
1153+
11111154
- The Ingress has to know how to retrieve the Service to then connect the Pods and route traffic.
11121155
- The Ingress retrieves the right Service by name and port exposed.
11131156
- The `service.port` of the Ingress should match the `port` of the Service
@@ -1185,6 +1228,7 @@ Source:
11851228
- `kubectl get pod <pod name>` is useful to extract the YAML definition of the Pod as stored in Kubernetes.
11861229
- `kubectl exec -ti <pod name>` -- bash is useful to run an interactive command within one of the containers of the Pod.
11871230
- Common errors:
1231+
11881232
- Startup errors include:
11891233
- _ImagePullBackoff_:
11901234
- The image name is invalid.
@@ -1196,7 +1240,9 @@ Source:
11961240
- _RegistryUnavailable_:
11971241
- _InvalidImageName_:
11981242
- Runtime errors include:
1243+
11991244
- _CrashLoopBackOff_:
1245+
12001246
- There's an error in the application that prevents from starting.
12011247
- You misconfigured the container.
12021248
- The Liveness probe failed too many times.
@@ -1206,6 +1252,7 @@ Source:
12061252
```
12071253

12081254
- _RunContainerError_:
1255+
12091256
- Mount a not-existent volume such as ConfigMap or Secrets
12101257
- Mount a read-only volume as read-write
12111258

@@ -1222,6 +1269,7 @@ Source:
12221269
- _SetupNetworkError_
12231270
- _TeardownNetworkError_
12241271
- _Pods in a Pending state_:
1272+
12251273
- The cluster doesn't have enough resources such as CPU and memory to run the Pod.
12261274
- The current Namespace has a ResourceQuota object and creating the Pod will make the Namespace go over the quota.
12271275
- The Pod is bound to a Pending PersistentVolumeClaim.
@@ -1232,13 +1280,15 @@ Source:
12321280
```
12331281

12341282
- _Pods in a not Ready state_:
1283+
12351284
- The Readiness probe is failing -> the Pod isn't attached to the Service, and no traffic is forwarded to that instance.
12361285

12371286
```shell
12381287
$ kubectl describe pod <pod-name>
12391288
```
12401289

12411290
- Troubleshooting Services:
1291+
12421292
- If Pods are Running and Ready, but you're still unable to receive a response from your app, you should check if the Service is configured correctly.
12431293
- Services are designed to route the traffic to Pods based on their labels.
12441294

@@ -1267,6 +1317,7 @@ Source:
12671317
````
12681318
12691319
- Troubleshooting Ingress:
1320+
12701321
- Pods - OK, Service - OK -> Check Ingress.
12711322
12721323
```shell

0 commit comments

Comments
 (0)