@ -0,0 +1,134 @@ | |||
# Kubernetes 101 | |||
## Docker vs. Kubernetes | |||
Docker helps you package applications into images, and execute them in containers. Kubernetes is a robust platform for containerized applications. It abstracts away the underlying network infrastructure and hardware required to run them, simplifying their deployment, scaling, and management. | |||
## Kubernetes from the container up | |||
### Pods | |||
The basic unit of a Kubernetes deployment is the **Pod**. A Pod encapsulates one or more containers. For example, the `basket` Pod specifies two containers: | |||
>`deployments.yaml` | |||
> | |||
>The first container runs the `eshop/basket.api` image: | |||
>```yaml | |||
>spec: | |||
> containers: | |||
> - name: basket | |||
> image: eshop/basket.api | |||
> env: | |||
> - name: ConnectionString | |||
> value: 127.0.0.1 | |||
>``` | |||
>Note the `ConnectionString` environment variable: containers within a Pod are networked via `localhost`. The second container runs the `redis` image: | |||
>```yaml | |||
>- name: basket-data | |||
> image: redis:3.2-alpine | |||
> ports: | |||
> - containerPort: 6379 | |||
>``` | |||
Placing `basket` and `basket-data` in the same Pod is reasonable here because the former requires the latter, and owns all its data. If we wanted to scale the service, however, it would be better to place the containers in separate Pods because the basket API and redis scale at different rates. | |||
If the containers were in separate Pods, they would no longer be able to communicate via `localhost`; a **Service** would be required. | |||
### Services | |||
Services expose Pods to external networks. For example, the `basket` Service exposes Pods with labels `app=eshop` and `component=basket` to the cluster at large: | |||
>`services.yaml` | |||
>```yaml | |||
>kind: Service | |||
>metadata: | |||
> ... | |||
> name: basket | |||
>spec: | |||
> ports: | |||
> - port: 80 | |||
> selector: | |||
> app: eshop | |||
> component: basket | |||
>``` | |||
Kubernetes's built-in DNS service resolves Service names to cluster-internal IP addresses. This allows the nginx frontend to proxy connections to the app's microservices by name: | |||
>`nginx.conf` | |||
>``` | |||
>location /basket-api { | |||
> proxy_pass http://basket; | |||
>``` | |||
The frontend Pod is different in that it needs to be exposed outside the cluster. This is accomplished with another Service: | |||
>`frontend.yaml` | |||
>```yaml | |||
>spec: | |||
> ports: | |||
> - port: 80 | |||
> targetPort: 8080 | |||
> selector: | |||
> app: eshop | |||
> component: frontend | |||
> type: LoadBalancer | |||
>``` | |||
`type: LoadBalancer` tells Kubernetes to expose the Service behind a load balancer appropriate for the cluster's platform. For Azure Container Service, this creates an Azure load balancer rule with a public IP. | |||
### Deployments | |||
Kubernetes uses Pods to organize containers, and Services to network them. It uses **Deployments** to organize creating, and modifying, Pods. A Deployment describes a state of one or more Pods. When a Deployment is created or modified, Kubernetes attempts to realize that state. | |||
The Deployments in this project are basic. Still, `deploy.ps1` shows some more advanced Deployment capabilities. For example, Deployments can be paused. Each Deployment of this app is paused at creation: | |||
>`deployments.yaml` | |||
>```yaml | |||
>kind: Deployment | |||
>spec: | |||
> paused: true | |||
>``` | |||
This allows the deployment script to change images before Kubernetes creates the Pods: | |||
>`deploy.ps1` | |||
>```powershell | |||
>kubectl set image -f deployments.yaml basket=$registry/basket.api ... | |||
>kubectl rollout resume -f deployments.yaml | |||
>``` | |||
### ConfigMaps | |||
A **ConfigMap** is a collection of key/value pairs commonly used to provide configuration information to Pods. The deployment script uses one to store the frontend's configuration: | |||
>`deploy.ps1` | |||
>``` | |||
>kubectl create configmap config-files from-file=nginx-conf=nginx.conf | |||
>``` | |||
This creates a ConfigMap named `config-files` with key `nginx-conf` whose value is the content of nginx.conf. The frontend Pod mounts that value as `/etc/nginx/nginx.conf`: | |||
>`frontend.yaml` | |||
>```yaml | |||
>spec: | |||
> containers: | |||
> - name: nginx | |||
> ... | |||
> volumeMounts: | |||
> - name: config | |||
> mountPath: /etc/nginx | |||
> volumes: | |||
> - name: config | |||
> configMap: | |||
> name: config-files | |||
> items: | |||
> - key: nginx-conf | |||
> path: nginx.conf | |||
>``` | |||
This facilitates rapid iteration better than other techniques, e.g. building an image to bake in configuration. | |||
The script also stores public URLs for the app's components in a ConfigMap: | |||
>`deploy.ps1` | |||
>```powershell | |||
>kubectl create configmap urls --from-literal=BasketUrl=http://$($frontendUrl)/basket-api ... | |||
>``` | |||
>Here's how the `webspa` Deployment uses it: | |||
> | |||
>`deployments.yaml` | |||
>```yaml | |||
>spec: | |||
> containers: | |||
> - name: webspa | |||
> ... | |||
> env: | |||
> ... | |||
> - name: BasketUrl | |||
> valueFrom: | |||
> configMapKeyRef: | |||
> name: urls | |||
> key: BasketUrl | |||
>``` | |||
### Further reading | |||
* [Kubernetes Concepts](https://kubernetes.io/docs/concepts/) | |||
* [kubectl for Docker Users](https://kubernetes.io/docs/user-guide/docker-cli-to-kubectl/) | |||
* [Kubernetes API reference](https://kubernetes.io/docs/api-reference/v1.5/) |
@ -0,0 +1,28 @@ | |||
# eShopOnContainers on Kubernetes | |||
The k8s directory contains Kubernetes configuration for the eShopOnContainers app and a PowerShell script to deploy it to a cluster. Each eShopOnContainers microservice has a deployment configuration in `deployments.yaml`, and is exposed to the cluster by a service in `services.yaml`. The microservices are exposed externally on individual routes (`/basket-api`, `/webmvc`, etc.) by an nginx reverse proxy specified in `frontend.yaml` and `nginx.conf`. | |||
## Prerequisites | |||
* A Kubernetes cluster. Follow Azure Container Service's [walkthrough](https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough) to create one. | |||
* A private Docker registry. Follow Azure Container Registry's [guide](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal) to create one. | |||
* Optionally, previous steps can be skipped if you run gen-k8s-env.ps1 script to automatically create the azure environment needed for kubernetes deployment. Azure cli 2.0 must be previously installed [installation guide](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). For example: | |||
>``` | |||
>./gen-k8s-env -resourceGroupName k8sGroup -location westeurope -registryName k8sregistry -orchestratorName k8s-cluster -dnsName k8s-dns | |||
>``` | |||
* A Docker development environment with `docker` and `docker-compose`. | |||
* Visit [docker.com](https://docker.com) to download the tools and set up the environment. Docker's [installation guide](https://docs.docker.com/engine/getstarted/step_one/#step-3-verify-your-installation) covers verifying your Docker installation. | |||
* The Kubernetes command line client, `kubectl`. | |||
* This can be installed with the `az` tool as described in the Azure Container Service [walkthrough](https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough). `az` is also helpful for getting the credentials `kubectl` needs to access your cluster. For other installation options, and information about configuring `kubectl` yourself, see the [Kubernetes documentation](https://kubernetes.io/docs/tasks/kubectl/install/). | |||
## Deploy the application with the deployment script | |||
1. Open a PowerShell command line at the `k8s` directory of your local eShopOnContainers repository. | |||
1. Ensure `docker`, `docker-compose`, and `kubectl` are on the path, and configured for your Docker machine and Kubernetes cluster. | |||
1. Run `deploy.ps1` with your registry information. The Docker username and password are provided by Azure Container Registry, and can be retrieved from the Azure portal. Optionally, ACR credentials can be obtained by running the following command: | |||
>``` | |||
>az acr credential show -n eshopregistry | |||
>``` | |||
Once the user and password are retrieved, run the following script for deployment. For example: | |||
>``` | |||
>./deploy.ps1 -registry myregistry.azurecr.io -dockerUser User -dockerPassword SecretPassword | |||
>``` | |||
The script will build the code and corresponding Docker images, push the latter to your registry, and deploy the application to your cluster. You can watch the deployment unfold from the Kubernetes web interface: run `kubectl proxy` and open a browser to [http://localhost:8001/ui](http://localhost:8001/ui) |
@ -0,0 +1,80 @@ | |||
Param( | |||
[parameter(Mandatory=$true)][string]$registry, | |||
[parameter(Mandatory=$true)][string]$dockerUser, | |||
[parameter(Mandatory=$true)][string]$dockerPassword | |||
) | |||
$requiredCommands = ("docker", "docker-compose", "kubectl") | |||
foreach ($command in $requiredCommands) { | |||
if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) { | |||
Write-Host "$command must be on path" -ForegroundColor Red | |||
exit | |||
} | |||
} | |||
Write-Host "Logging in to $registry" -ForegroundColor Yellow | |||
docker login -u $dockerUser -p $dockerPassword $registry | |||
if (-not $LastExitCode -eq 0) { | |||
Write-Host "Login failed" -ForegroundColor Red | |||
exit | |||
} | |||
# create registry key secret | |||
kubectl create secret docker-registry registry-key ` | |||
--docker-server=$registry ` | |||
--docker-username=$dockerUser ` | |||
--docker-password=$dockerPassword ` | |||
--docker-email=not@used.com | |||
# start sql, rabbitmq, frontend deployments | |||
kubectl create configmap config-files --from-file=nginx-conf=nginx.conf | |||
kubectl label configmap config-files app=eshop | |||
kubectl create -f sql-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml | |||
Write-Host "Building and publishing eShopOnContainers..." -ForegroundColor Yellow | |||
dotnet restore ../eShopOnContainers-ServicesAndWebApps.sln | |||
dotnet publish -c Release -o obj/Docker/publish ../eShopOnContainers-ServicesAndWebApps.sln | |||
Write-Host "Building Docker images..." -ForegroundColor Yellow | |||
docker-compose -p .. -f ../docker-compose.yml build | |||
Write-Host "Pushing images to $registry..." -ForegroundColor Yellow | |||
$services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "webmvc", "webspa") | |||
foreach ($service in $services) { | |||
docker tag eshop/$service $registry/eshop/$service | |||
docker push $registry/eshop/$service | |||
} | |||
Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow | |||
while ($true) { | |||
$frontendUrl = kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}" | |||
if ([bool]($frontendUrl -as [ipaddress])) { | |||
break | |||
} | |||
Start-Sleep -s 15 | |||
} | |||
kubectl create configmap urls ` | |||
--from-literal=BasketUrl=http://$($frontendUrl)/basket-api ` | |||
--from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api ` | |||
--from-literal=IdentityUrl=http://$($frontendUrl)/identity ` | |||
--from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api ` | |||
--from-literal=MvcClient=http://$($frontendUrl)/webmvc ` | |||
--from-literal=SpaClient=http://$($frontendUrl) | |||
kubectl label configmap urls app=eshop | |||
Write-Host "Creating deployments..." | |||
kubectl apply -f deployments.yaml | |||
# update deployments with the private registry before k8s tries to pull images | |||
# (deployment templating, or Helm, would obviate this) | |||
kubectl set image -f deployments.yaml ` | |||
basket=$registry/eshop/basket.api ` | |||
catalog=$registry/eshop/catalog.api ` | |||
identity=$registry/eshop/identity.api ` | |||
ordering=$registry/eshop/ordering.api ` | |||
webmvc=$registry/eshop/webmvc ` | |||
webspa=$registry/eshop/webspa | |||
kubectl rollout resume -f deployments.yaml | |||
Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow |
@ -0,0 +1,236 @@ | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: basket | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: basket | |||
spec: | |||
containers: | |||
- name: basket | |||
image: eshop/basket.api | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80/basket-api | |||
- name: ConnectionString | |||
value: 127.0.0.1 | |||
- name: EventBusConnection | |||
value: rabbitmq | |||
- name: IdentityUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: IdentityUrl | |||
ports: | |||
- containerPort: 80 | |||
- name: basket-data | |||
image: redis:3.2-alpine | |||
ports: | |||
- containerPort: 6379 | |||
imagePullSecrets: | |||
- name: registry-key | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: catalog | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: catalog | |||
spec: | |||
containers: | |||
- name: catalog | |||
image: eshop/catalog.api | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80/catalog-api | |||
- name: ConnectionString | |||
value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word" | |||
- name: EventBusConnection | |||
value: rabbitmq | |||
- name: ExternalCatalogBaseUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: CatalogUrl | |||
ports: | |||
- containerPort: 80 | |||
imagePullSecrets: | |||
- name: registry-key | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: identity | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: identity | |||
spec: | |||
containers: | |||
- name: identity | |||
image: eshop/identity.api | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80/identity | |||
- name: ConnectionStrings__DefaultConnection | |||
value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word" | |||
- name: MvcClient | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: MvcClient | |||
- name: SpaClient | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: SpaClient | |||
ports: | |||
- containerPort: 80 | |||
imagePullSecrets: | |||
- name: registry-key | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: ordering | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: ordering | |||
spec: | |||
containers: | |||
- name: ordering | |||
image: eshop/ordering.api | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80/ordering-api | |||
- name: ConnectionString | |||
value: "Server=sql-data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" | |||
- name: EventBusConnection | |||
value: rabbitmq | |||
- name: IdentityUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: IdentityUrl | |||
ports: | |||
- containerPort: 80 | |||
imagePullSecrets: | |||
- name: registry-key | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webmvc | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: webmvc | |||
spec: | |||
containers: | |||
- name: webmvc | |||
image: eshop/webmvc | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80/webmvc | |||
- name: BasketUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: BasketUrl | |||
- name: CallBackUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: MvcClient | |||
- name: CatalogUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: CatalogUrl | |||
- name: IdentityUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: IdentityUrl | |||
- name: OrderingUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: OrderingUrl | |||
ports: | |||
- containerPort: 80 | |||
imagePullSecrets: | |||
- name: registry-key | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webspa | |||
spec: | |||
paused: true | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: webspa | |||
spec: | |||
containers: | |||
- name: webspa | |||
image: eshop/webspa | |||
imagePullPolicy: Always | |||
env: | |||
- name: ASPNETCORE_URLS | |||
value: http://0.0.0.0:80 | |||
- name: BasketUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: BasketUrl | |||
- name: CallBackUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: SpaClient | |||
- name: CatalogUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: CatalogUrl | |||
- name: IdentityUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: IdentityUrl | |||
- name: OrderingUrl | |||
valueFrom: | |||
configMapKeyRef: | |||
name: urls | |||
key: OrderingUrl | |||
ports: | |||
- containerPort: 80 | |||
imagePullSecrets: | |||
- name: registry-key |
@ -0,0 +1,47 @@ | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: frontend | |||
name: frontend | |||
spec: | |||
ports: | |||
- port: 80 | |||
targetPort: 8080 | |||
selector: | |||
app: eshop | |||
component: frontend | |||
type: LoadBalancer | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: frontend | |||
spec: | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: frontend | |||
spec: | |||
containers: | |||
- name: nginx | |||
image: nginx:1.11.10-alpine | |||
imagePullPolicy: IfNotPresent | |||
ports: | |||
- containerPort: 8080 | |||
lifecycle: | |||
preStop: | |||
exec: | |||
command: ["/usr/sbin/nginx","-s","quit"] | |||
volumeMounts: | |||
- name: config | |||
mountPath: /etc/nginx | |||
volumes: | |||
- name: config | |||
configMap: | |||
name: config-files | |||
items: | |||
- key: nginx-conf | |||
path: nginx.conf |
@ -0,0 +1,25 @@ | |||
Param( | |||
[parameter(Mandatory=$true)][string]$resourceGroupName, | |||
[parameter(Mandatory=$true)][string]$location, | |||
[parameter(Mandatory=$true)][string]$registryName, | |||
[parameter(Mandatory=$true)][string]$orchestratorName, | |||
[parameter(Mandatory=$true)][string]$dnsName | |||
) | |||
# Create resource group | |||
Write-Host "Creating resource group..." -ForegroundColor Yellow | |||
az group create --name=$resourceGroupName --location=$location | |||
# Create Azure Container Registry | |||
Write-Host "Creating Azure Container Registry..." -ForegroundColor Yellow | |||
az acr create -n $registryName -g $resourceGroupName -l $location --admin-enabled true --sku Basic | |||
# Create kubernetes orchestrator | |||
Write-Host "Creating kubernetes orchestrator..." -ForegroundColor Yellow | |||
az acs create --orchestrator-type=kubernetes --resource-group $resourceGroupName --name=$orchestratorName --dns-prefix=$dnsName --generate-ssh-keys | |||
# Retrieve kubernetes cluster configuration and save it under ~/.kube/config | |||
az acs kubernetes get-credentials --resource-group=$resourceGroupName --name=$orchestratorName | |||
# Show ACR credentials | |||
az acr credential show -n $registryName |
@ -0,0 +1,74 @@ | |||
pid /tmp/nginx.pid; | |||
worker_processes 1; | |||
events { | |||
worker_connections 1024; | |||
} | |||
http { | |||
server_tokens off; | |||
add_header X-Frame-Options SAMEORIGIN; | |||
add_header X-Content-Type-Options nosniff; | |||
add_header X-XSS-Protection "1; mode=block"; | |||
client_body_temp_path /tmp/client_body; | |||
fastcgi_temp_path /tmp/fastcgi_temp; | |||
proxy_temp_path /tmp/proxy_temp; | |||
scgi_temp_path /tmp/scgi_temp; | |||
uwsgi_temp_path /tmp/uwsgi_temp; | |||
gzip on; | |||
gzip_comp_level 6; | |||
gzip_min_length 1024; | |||
gzip_buffers 4 32k; | |||
gzip_types text/plain application/javascript text/css; | |||
gzip_vary on; | |||
keepalive_timeout 65; | |||
proxy_buffer_size 128k; | |||
proxy_buffers 4 256k; | |||
proxy_busy_buffers_size 256k; | |||
server { | |||
listen 8080; | |||
location /basket-api { | |||
proxy_pass http://basket; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
location /catalog-api { | |||
proxy_pass http://catalog; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
location /identity { | |||
proxy_pass http://identity; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
location /ordering-api { | |||
proxy_pass http://ordering; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
location /webmvc { | |||
proxy_pass http://webmvc; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
location / { | |||
proxy_pass http://webspa; | |||
proxy_redirect off; | |||
proxy_set_header Host $host; | |||
} | |||
} | |||
} |
@ -0,0 +1,30 @@ | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: rabbitmq | |||
name: rabbitmq | |||
spec: | |||
ports: | |||
- port: 5672 | |||
selector: | |||
app: eshop | |||
component: rabbitmq | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: rabbitmq | |||
spec: | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: rabbitmq | |||
spec: | |||
containers: | |||
- name: rabbitmq | |||
image: rabbitmq:3.6.9-alpine | |||
ports: | |||
- containerPort: 5672 |
@ -0,0 +1,83 @@ | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: basket | |||
name: basket | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: basket | |||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: catalog | |||
name: catalog | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: catalog | |||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: identity | |||
name: identity | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: identity | |||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: ordering | |||
name: ordering | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: ordering | |||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: webmvc | |||
name: webmvc | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: webmvc | |||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: webspa | |||
name: webspa | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: eshop | |||
component: webspa |
@ -0,0 +1,33 @@ | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: sql-data | |||
name: sql-data | |||
spec: | |||
ports: | |||
- port: 1433 | |||
selector: | |||
app: eshop | |||
component: sql-data | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: sql-data | |||
spec: | |||
template: | |||
metadata: | |||
labels: | |||
app: eshop | |||
component: sql-data | |||
spec: | |||
containers: | |||
- name: sql-data | |||
image: microsoft/mssql-server-linux:ctp1-3 | |||
env: | |||
- name: ACCEPT_EULA | |||
value: "Y" | |||
- name: SA_PASSWORD | |||
value: Pass@word |
@ -1,16 +1,16 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net.Http; | |||
using System.Net.Http; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.Resilience.Http | |||
{ | |||
public interface IHttpClient | |||
{ | |||
HttpClient Inst { get; } | |||
Task<string> GetStringAsync(string uri); | |||
Task<HttpResponseMessage> PostAsync<T>(string uri, T item); | |||
Task<HttpResponseMessage> DeleteAsync(string uri); | |||
Task<string> GetStringAsync(string uri, string authorizationToken = null, string authorizationMethod = "Bearer"); | |||
Task<HttpResponseMessage> PostAsync<T>(string uri, T item, string authorizationToken = null, string requestId = null, string authorizationMethod = "Bearer"); | |||
Task<HttpResponseMessage> DeleteAsync(string uri, string authorizationToken = null, string requestId = null, string authorizationMethod = "Bearer"); | |||
Task<HttpResponseMessage> PutAsync<T>(string uri, T item, string authorizationToken = null, string requestId = null, string authorizationMethod = "Bearer"); | |||
} | |||
} |
@ -1,10 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.Resilience.Http | |||
{ | |||
public class ResiliencePolicy | |||
{ | |||
} | |||
} |
@ -1,13 +1,14 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries | |||
{ | |||
using System.Collections.Generic; | |||
using System.Threading.Tasks; | |||
public interface IOrderQueries | |||
{ | |||
Task<dynamic> GetOrderAsync(int id); | |||
Task<dynamic> GetOrdersAsync(); | |||
Task<IEnumerable<dynamic>> GetOrdersAsync(); | |||
Task<dynamic> GetCardTypesAsync(); | |||
Task<IEnumerable<dynamic>> GetCardTypesAsync(); | |||
} | |||
} |
@ -0,0 +1,25 @@ | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Hosting; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Ordering.API.Infrastructure.Middlewares | |||
{ | |||
public class FailingStartupFilter : IStartupFilter | |||
{ | |||
public FailingStartupFilter() | |||
{ | |||
} | |||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) | |||
{ | |||
return app => | |||
{ | |||
app.UseFailingMiddleware(); | |||
next(app); | |||
}; | |||
} | |||
} | |||
} |
@ -0,0 +1,23 @@ | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Ordering.API.Infrastructure.Middlewares; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.AspNetCore.Hosting | |||
{ | |||
public static class WebHostBuildertExtensions | |||
{ | |||
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, string path) | |||
{ | |||
builder.ConfigureServices(services => | |||
{ | |||
services.AddSingleton<IStartupFilter>(new FailingStartupFilter()); | |||
}); | |||
return builder; | |||
} | |||
} | |||
} |
@ -0,0 +1,68 @@ | |||
namespace WebMVC.Infrastructure | |||
{ | |||
public static class API | |||
{ | |||
public static class Basket | |||
{ | |||
public static string GetBasket(string baseUri, string basketId) | |||
{ | |||
return $"{baseUri}/{basketId}"; | |||
} | |||
public static string UpdateBasket(string baseUri) | |||
{ | |||
return baseUri; | |||
} | |||
public static string CleanBasket(string baseUri, string basketId) | |||
{ | |||
return $"{baseUri}/{basketId}"; | |||
} | |||
} | |||
public static class Order | |||
{ | |||
public static string GetOrder(string baseUri, string orderId) | |||
{ | |||
return $"{baseUri}/{orderId}"; | |||
} | |||
public static string GetAllMyOrders(string baseUri) | |||
{ | |||
return baseUri; | |||
} | |||
public static string AddNewOrder(string baseUri) | |||
{ | |||
return $"{baseUri}/new"; | |||
} | |||
} | |||
public static class Catalog | |||
{ | |||
public static string GetAllCatalogItems(string baseUri, int page, int take, int? brand, int? type) | |||
{ | |||
var filterQs = ""; | |||
if (brand.HasValue || type.HasValue) | |||
{ | |||
var brandQs = (brand.HasValue) ? brand.Value.ToString() : "null"; | |||
var typeQs = (type.HasValue) ? type.Value.ToString() : "null"; | |||
filterQs = $"/type/{typeQs}/brand/{brandQs}"; | |||
} | |||
return $"{baseUri}items{filterQs}?pageIndex={page}&pageSize={take}"; | |||
} | |||
public static string GetAllBrands(string baseUri) | |||
{ | |||
return $"{baseUri}catalogBrands"; | |||
} | |||
public static string GetAllTypes(string baseUri) | |||
{ | |||
return $"{baseUri}catalogTypes"; | |||
} | |||
} | |||
} | |||
} |