Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| en:modul:m321_aws:topics:08 [2025/09/27 22:58] – dgaravaldi | en:modul:m321_aws:topics:08 [2025/10/22 16:32] (aktuell) – dgaravaldi | ||
|---|---|---|---|
| Zeile 22: | Zeile 22: | ||
| \\ | \\ | ||
| - | ===== Example 1: Kubernetes Deployment (YAML) ===== | + | ==== Example 1: Deployment-Elements in YAML explained ==== |
| + | < | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: calculator-deployment | ||
| + | labels: | ||
| + | app: calculator | ||
| + | spec: | ||
| + | replicas: 3 (3) | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: calculator | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: calculator | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: calculator | ||
| + | image: gcr.io/ | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| + | |||
| + | |||
| + | In this YAML configuration, | ||
| + | \\ | ||
| + | -We have defined a Kubernetes resource of the Deployment type from the '' | ||
| + | -The unique deployment name is '' | ||
| + | -We have defined that there should be exactly '' | ||
| + | -'' | ||
| + | -'' | ||
| + | -Each Pod is labeled with '' | ||
| + | -Each Pod contains a Docker container '' | ||
| + | -A Docker container was created from the image called '' | ||
| + | -The Pod exposes container port '' | ||
| + | |||
| + | To install the deployment, run the following command: | ||
| + | |||
| + | < | ||
| + | $ kubectl apply -f deployment.yaml | ||
| + | </ | ||
| + | |||
| + | You can check that the three Pods, each containing one Docker container, have been created: | ||
| + | |||
| + | < | ||
| + | $ kubectl get pods | ||
| + | NAME READY STATUS | ||
| + | calculator-deployment-dccdf8756-h2l6c 1/1 | ||
| + | calculator-deployment-dccdf8756-tgw48 1/1 | ||
| + | calculator-deployment-dccdf8756-vtwjz 1/1 | ||
| + | </ | ||
| + | |||
| + | Each Pod runs a Docker container. We can check its logs by using the following command: | ||
| + | < | ||
| + | $ kubectl logs pods/ | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | ==== Example 2: Kubernetes Deployment (YAML) ==== | ||
| As an example, containerized python app is used. The parameter '' | As an example, containerized python app is used. The parameter '' | ||
| Zeile 48: | Zeile 109: | ||
| </ | </ | ||
| \\ | \\ | ||
| - | ===== Example | + | ==== Example |
| The previous example declared only the deployment. In this example, we add the corresponding service. | The previous example declared only the deployment. In this example, we add the corresponding service. | ||
| Zeile 84: | Zeile 145: | ||
| targetPort: 8080 | targetPort: 8080 | ||
| type: ClusterIP | type: ClusterIP | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ===== Service types ===== | ||
| + | As a recapture on how your application can be accessed from the outside, we need to start with the types of Kubernetes Services. You can use four different service types, as follows: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | While LoadBalancer seems to be the simplest solution, it has two drawbacks: | ||
| + | * It's not always available, for example, if you're using minikube. | ||
| + | * External public IPs are usually expensive. A different solution is to use a '' | ||
| + | |||
| + | < | ||
| + | $ kubectl get service my-python-service | ||
| + | NAME | ||
| + | my-python-service | ||
| + | </ | ||
| + | |||
| + | You can see that port '' | ||
| + | |||
| + | The IP address of your Kubernetes node depends on your installation. In the case of minikube, you can check it with the minikube ip command: | ||
| + | |||
| + | < | ||
| + | $ kubectl get nodes -o jsonpath=' | ||
| + | 35.192.180.252 35.232.125.195 104.198.131.248 | ||
| + | </ | ||
| + | To check that you can access '' | ||
| + | |||
| + | < | ||
| + | $ curl http://< | ||
| </ | </ | ||