Skip to content

Commit 4aecc07

Browse files
committed
Add Dockerfile and README for Azure Container Registry setup with example usage
1 parent 869851e commit 4aecc07

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
"version": "lts",
2525
"pnpmVersion": "latest",
2626
"nvmVersion": "latest"
27+
},
28+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
29+
"moby": true,
30+
"azureDnsAutoDetection": true,
31+
"installDockerBuildx": true,
32+
"installDockerComposeSwitch": true,
33+
"version": "latest",
34+
"dockerDashComposeVersion": "latest"
2735
}
2836
},
2937
"customizations": {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginx:alpine
2+
3+
COPY index.html /usr/share/nginx/html/index.html
4+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Azure Container Registry
2+
3+
Es común que cuando trabajamos con Azure Kubernetes Services también utilicemos Azure Container Registry para almacenar nuestras imágenes de contenedores. Este ofrece un montón de ventajas no solo relacionadas con AKS sino en general.
4+
5+
## Crear un Azure Container Registry
6+
7+
Lo primero que vamos a hacer es crearnos un recurso de este tipo, en el mismo grupo de recursos donde tenemos nuestro clúster:
8+
9+
```bash
10+
RESOURCE_GROUP="bootcamp-lemoncode"
11+
ACR_NAME="lemoncodeacr"
12+
LOCATION="spaincentral"
13+
14+
az acr create -n ${ACR_NAME} -g ${RESOURCE_GROUP} --sku Basic --location ${LOCATION}
15+
```
16+
17+
Una vez que ya lo tienes, en este se pueden o bien generar imágenes en local y luego publicarlas:
18+
19+
```bash
20+
az acr login -n ${ACR_NAME}
21+
docker build -t ${ACR_NAME}.azurecr.io/hello-world:v1 04-cloud/00-aks/02-azure-container-registry
22+
docker push ${ACR_NAME}.azurecr.io/hello-world:v1
23+
```
24+
25+
O bien, puedes hacer uso de la funcionalidad de `acr build` que te permite hacer el build y el push en un solo paso:
26+
27+
```bash
28+
az acr build -r ${ACR_NAME} -t ${ACR_NAME}.azurecr.io/hello-lemoncode:{{.Run.ID}} 04-cloud/00-aks/02-azure-container-registry
29+
```
30+
Esto además significa que no necesitas tener Docker instalado en tu máquina, ya que el proceso de build se hace en la nube. Y lo chulo de esto es que podemos usar diferentes plataformas de build como por ejemplo Windows, Linux o ARM.
31+
32+
```bash
33+
az acr build -r ${ACR_NAME} -t ${ACR_NAME}.azurecr.io/hello-lemoncode:linux-arm 04-cloud/00-aks/02-azure-container-registry --platform linux/arm/v7
34+
```
35+
36+
## Usar el Azure Container Registry en AKS
37+
38+
Lo chulo de todo esto es que AKS ya viene preparado para trabajar con ACR, por lo que no necesitas hacer nada especial para que funcione. Lo único que tienes que hacer es decirle a tu clúster que use tu ACR:
39+
40+
```bash
41+
AKS_NAME="lemoncode-cluster"
42+
43+
az aks update -n ${AKS_NAME} -g ${RESOURCE_GROUP} --attach-acr ${ACR_NAME}
44+
```
45+
46+
Y con esto ya puedes hacer uso de tus imágenes almacenadas en tu ACR en tu clúster de AKS. Para probarlo, puedes desplegar un pod que haga uso de una de estas imágenes:
47+
48+
```bash
49+
az aks get-credentials -g ${RESOURCE_GROUP} -n ${AKS_NAME} --overwrite-existing
50+
51+
LAST_TAG=$(az acr repository show-tags -n ${ACR_NAME} --repository hello-world --orderby time_desc --top 1 --output tsv)
52+
53+
echo "La última imagen de hello-world es ${LAST_TAG}"
54+
55+
kubectl run hello-lemoncode --image=${ACR_NAME}.azurecr.io/hello-world:${LAST_TAG}
56+
57+
kubectl get pods -w
58+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Beautiful Animation</title>
7+
<style>
8+
body {
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
height: 100vh;
13+
margin: 0;
14+
background-color: #282c34;
15+
color: white;
16+
font-family: Arial, sans-serif;
17+
}
18+
.box {
19+
width: 100px;
20+
height: 100px;
21+
background-color: #61dafb;
22+
animation: bounce 2s infinite;
23+
}
24+
@keyframes bounce {
25+
0%, 20%, 50%, 80%, 100% {
26+
transform: translateY(0);
27+
}
28+
40% {
29+
transform: translateY(-150px);
30+
}
31+
60% {
32+
transform: translateY(-75px);
33+
}
34+
}
35+
</style>
36+
</head>
37+
<body>
38+
<div class="box"></div>
39+
</body>
40+
</html>
File renamed without changes.

0 commit comments

Comments
 (0)