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/26 16:06] – dgaravaldi | en:modul:m321_aws:topics:08 [2025/10/22 16:32] (aktuell) – dgaravaldi | ||
|---|---|---|---|
| Zeile 14: | Zeile 14: | ||
| ===== What does declaration look like? ===== | ===== What does declaration look like? ===== | ||
| In most cases, the '' | In most cases, the '' | ||
| + | \\ | ||
| + | A great help is to get the declaration from existing Kubernetes objects. When you request the Kubernetes resource using the '' | ||
| + | |||
| + | The '' | ||
| + | |||
| + | It's recommend using YAML as the format for these declarations. You could use JSON, but YAML allows you __to add comments into the declarations__, | ||
| + | |||
| + | \\ | ||
| + | ==== 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 '' | ||
| + | |||
| + | < | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: my-python-app | ||
| + | spec: | ||
| + | replicas: 1 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: my-python-app | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: my-python-app | ||
| + | spec: | ||
| + | terminationGracePeriodSeconds: | ||
| + | containers: | ||
| + | - name: app | ||
| + | image: your-image: | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| + | \\ | ||
| + | ==== Example 3: Kubernetes Deployment + Service (YAML) ==== | ||
| + | The previous example declared only the deployment. In this example, we add the corresponding service. | ||
| + | |||
| + | < | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: my-python-app | ||
| + | spec: | ||
| + | replicas: 1 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: my-python-app | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: my-python-app | ||
| + | spec: | ||
| + | terminationGracePeriodSeconds: | ||
| + | containers: | ||
| + | - name: app | ||
| + | image: your-image: | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | --- | ||
| + | apiVersion: v1 | ||
| + | kind: Service | ||
| + | metadata: | ||
| + | name: my-python-service | ||
| + | spec: | ||
| + | selector: | ||
| + | app: my-python-app | ||
| + | ports: | ||
| + | - port: 8080 | ||
| + | targetPort: 8080 | ||
| + | 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://< | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | Based on " | ||
| + | |||
| + | [[https:// | ||