NOTE: This demo requires that you're running the Azure CLI version 2.0.75 or later. Run az --version
to find the version. Click here if you need to install or upgrade.
Portions of this demo are sourced from https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-deploy-application
This demo produces linux habitat artifacts and linux containers. Running the build steps below requires a linux or macos environment.
- A linux or macos workstation (does not work on Windows)
azure-cli
>= 2.0.75docker
>= 19.0.0chef habitat
>= 0.83.0
Clone this repo, and navigate to the root. Then make a build and export it to docker
git clone <this url>
cd national-parks
hab studio enter
build
source results/last_build.env
hab pkg export docker results/$pkg_artifact
We can pull mongodb from the chef-maintained habitat depot
hab pkg install core/mongodb/3.2.10
hab pkg export docker core/mongodb/3.2.10
This is a noop hab service we can export to docker and use as a permanent peer in kubernetes see here for details
cd examples/kubernetes-hab-bastion
hab studio enter
build
source results/last_build.env
hab pkg export docker results/$pkg_artifact
Use the directions here to test this with docker compose.
az login
az group create --name exampledemo --location westus
NOTE: replace exampledemo
with a name of your choice.
az acr create --resource-group exampledemo --name exampleacr --sku Basic
NOTE 1: Replace exampledemo
with your resource group name, and exampleacr
with a name of your choice.
NOTE 2: ALSO, the ACR name must be alphanumeric (no dashes or hyphens). sku is compute size, listed here
NOTE 3: This ACR name must be unique to you and your project as it lives in a global public namespace.
az acr login --name exampleacr
az acr list --resource-group exampledemo --output table
docker tag jvdemo/national-parks:7.0.0 exampleacr.azurecr.io/national-parks:7.0.0
docker push exampleacr.azurecr.io/national-parks:7.0.0
docker tag core/mongodb:3.2.10 exampleacr.azurecr.io/mongodb:3.2.10
docker push exampleacr.azurecr.io/mongodb:3.2.10
docker tag jvdemo/hab_bastion:latest exampleacr.azurecr.io/hab_bastion:latest
docker push exampleacr.azurecr.io/hab_bastion:latest
You now have a container image that is stored in a private Azure Container Registry instance. You can view it with the following:
az acr repository list --name exampleacr --output table
az aks install-cli
az aks create \
--resource-group exampledemo \
--name exampleaks \
--node-count 2 \
--generate-ssh-keys \
--attach-acr exampleacr
NOTE 1: Remember to replace example
with a name of your choice.
NOTE 2: If you get a authorization error, you may have to login to azure again by running az login
.
az aks get-credentials --resource-group exampledemo --name exampleaks
(stores creds in $HOME/.kube/config
)
Replace my namespaces with what you created.
(Replace any line that looks like: image: exampleacr.azurecr.io/mongodb:3.2.10
with your ACR ie: youracr.azurecr.io/mongodb:3.2.10
)
vi examples/k8s-manifest-with-bastion.yml
kubectl apply -f examples/k8s-manifest-with-bastion.yml
Get the IP (may have to run multiple times)
kubectl get service
Open in browser
- Update an index page (
cp red-index.html src/main/webapp/index.html
) - Bump package version to 7.1.0 (
vi habitat/plan.sh
) - Produce a new build:
hab studio enter
build
hab pkg export kubernetes jvdemo/national-parks
- Tag and upload it (outside of studio)
docker tag jvdemo/national-parks:7.1.0 exampleacr.azurecr.io/national-parks:7.1.0
docker push exampleacr.azurecr.io/national-parks:7.1.0
- Update kubernetes cluster with new version
kubectl set image deployment national-parks-app national-parks-app=exampleacr.azurecr.io/national-parks:7.1.0
- Go into the national parks directory and run:
kubectl delete -f examples/k8s-manifest-with-bastion.yml
- Go into azure and delete the resource group you created (
exampledemo
)