{
    "id": "05e61130-cf67-48f3-89b3-44a04e5a5f43",
    "name": "Deploy a Container to Kubernetes",
    "slug": "deploy-a-container-to-kubernetes",
    "status": "published",
    "lab_type": "azure",
    "is_sample": false,
    "duration_in_seconds": 1200,
    "metadata": {},
    "session": null,
    "company": "a491bc32-c056-4946-9169-cc053387bada",
    "created": "2020-08-11T12:14:07.111478Z",
    "modified": "2023-10-03T18:57:47.945294Z",
    "is_beta": false,
    "lab_objectives": [],
    "main_learning_area": null,
    "learning_areas": [],
    "categories": [],
    "tags": [],
    "difficulty": null,
    "is_web_access": false,
    "is_lab_experience": false,
    "is_featured": false,
    "cve": null,
    "severity": null,
    "year": null,
    "classification": null,
    "is_trackable": false,
    "cpe_credits": null,
    "is_skill_check": false,
    "external_url": "https://portal.azure.com/",
    "solution_video": "aaabd5d0-3d90-4bd3-9f49-c60b9a19aa3e",
    "explanation_video": null,
    "description": "# Task: Deploy a Container to Kubernetes\n\n## Video: Deploy a Web Site to an Azure Kubernetes Service\n\n**Estimated time:** 20 minutes for task\n\n## Goal\n\nCreate a Kubernetes manifest and deploy it to an Azure Kubernetes service.\n\n## Pre-requisites\n\n1. Azure subscription\n2. Azure container registry with a custom image\n3. Azure Kubernetes service with the ACRPull role on the ACR.\n\n## Requirements\n\n1. Create a Kubernetes manifest file\n2. Deploy a Kubernetes manifest file\n3. Verify the deployment\n\n---\n\n## Requirement 1: Create a Kubernetes manifest file\n\nFor this requirement you will create a manifest file to deploy the custom image stored in your ACR.  You will deploy three instances of the container with a load balanced front end.\n\n- Use a text editor to create a manifest file named **task-kube-app.yaml**.\n- Enter the following text into the file and save it:\n\n  ````yaml\n  apiVersion: apps/v1beta1\n  kind: Deployment\n  metadata:\n    name: pythonserver\n  spec:\n    replicas: 3\n    template:\n      metadata:\n        labels:\n          app: pythonserver\n      spec:\n        nodeSelector:\n          \"beta.kubernetes.io/os\": linux\n        containers:\n        - name: service\n          image: <your ACR server>/taskimage:1.0\n          ports:\n          - containerPort: 80\n          resources:\n            requests:\n              cpu: 250m\n            limits:\n              cpu: 500m\n  ---\n  apiVersion: v1\n  kind: Service\n  metadata:\n    name: service-endpoint\n  spec:\n    type: LoadBalancer\n    ports:\n    - port: 80\n    selector:\n      app: pythonserver\n  ````\n\n  *Note: Be sure to use your ACR server name for the image attribute.  Also, be very careful with indentation, yaml is a bit picky.*\n\n## Requirement 2: Deploy a Kubernetes manifest file\n\nFor this requirement you will use the Kubernetes CLI (kubectl) to deploy your manifest file. The steps below assume you are using the Azure bash cloud shell to complete the requirement.  If you have both the Azure CLI and the Kubernetes CLI installed locally, you can complete the requirement locally.\n\n- Open Azure cloud shell\n- Upload the **task-kube-app.yaml** file to cloud shell.  You can use the cloud shell menu or drag and drop the file onto cloud shell.\n- Run the following command to load the AKS credentials:\n\n  ```bash\n  az aks get-credentials -n kubernetes -g 'task-kubernetes'\n  ```\n\n- Run the following command to deploy the Kubernetes manifest:\n  \n  ````bash\n    kubectl apply -f ./task-kube-app.yaml\n  ````\n\n## Requirement 3: Verify the deployment\n\nFor this requirement you will monitor the kubernetes service to verify that the pods are running and that the service gets a public IP address.  You will then browse to the public IP address and confirm that you get the expected result.\n\n- Verify that three pods are running:\n\n  ````sh\n  kubectl get pod\n  ````\n\n- Verify that the service has a public IP address.  This may take a bit of time so the **--watch** option will update the output when the IP address is assigned.\n\n  ````bash\n  kubectl get service service-endpoint --watch\n  ````\n\n  *Note: Once the public IP shows up, press Ctrl-C to step watching.*\n\n- Open a browser tab and navigate to the public IP address of the service.\n  \n  *Note: Refreshing the page should return a different result. Each pod (instance) is assigned a different host name and the service will \"round-robin\" between them.*\n  \n## Clean up\n\n- Delete the **task-kubernetes** resource group.\n\n  *Note: Other tasks use a virtual machine with Docker installed and this registry.  If you plan on completing other container related exercises, you may want to de-allocate the virtual machine rather than removing it, likewise you may not want to delete the registry yet.*\n\n## Solution\n\nHaving trouble completing this task?  View the demonstration video to see how to do it.",
    "description_html": "<h1>Task: Deploy a Container to Kubernetes</h1>\n<h2>Video: Deploy a Web Site to an Azure Kubernetes Service</h2>\n<p><strong>Estimated time:</strong> 20 minutes for task</p>\n<h2>Goal</h2>\n<p>Create a Kubernetes manifest and deploy it to an Azure Kubernetes service.</p>\n<h2>Pre-requisites</h2>\n<ol>\n<li>Azure subscription</li>\n<li>Azure container registry with a custom image</li>\n<li>Azure Kubernetes service with the ACRPull role on the ACR.</li>\n</ol>\n<h2>Requirements</h2>\n<ol>\n<li>Create a Kubernetes manifest file</li>\n<li>Deploy a Kubernetes manifest file</li>\n<li>Verify the deployment</li>\n</ol>\n<hr />\n<h2>Requirement 1: Create a Kubernetes manifest file</h2>\n<p>For this requirement you will create a manifest file to deploy the custom image stored in your ACR.  You will deploy three instances of the container with a load balanced front end.</p>\n<ul>\n<li>Use a text editor to create a manifest file named <strong>task-kube-app.yaml</strong>.</li>\n<li>Enter the following text into the file and save it:</li>\n</ul>\n<pre class=\"codehilite\"><code class=\"language-yaml\">apiVersion: apps/v1beta1\nkind: Deployment\nmetadata:\n  name: pythonserver\nspec:\n  replicas: 3\n  template:\n    metadata:\n      labels:\n        app: pythonserver\n    spec:\n      nodeSelector:\n        \"beta.kubernetes.io/os\": linux\n      containers:\n      - name: service\n        image: &lt;your ACR server&gt;/taskimage:1.0\n        ports:\n        - containerPort: 80\n        resources:\n          requests:\n            cpu: 250m\n          limits:\n            cpu: 500m\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: service-endpoint\nspec:\n  type: LoadBalancer\n  ports:\n  - port: 80\n  selector:\n    app: pythonserver</code></pre>\n\n<p><em>Note: Be sure to use your ACR server name for the image attribute.  Also, be very careful with indentation, yaml is a bit picky.</em></p>\n<h2>Requirement 2: Deploy a Kubernetes manifest file</h2>\n<p>For this requirement you will use the Kubernetes CLI (kubectl) to deploy your manifest file. The steps below assume you are using the Azure bash cloud shell to complete the requirement.  If you have both the Azure CLI and the Kubernetes CLI installed locally, you can complete the requirement locally.</p>\n<ul>\n<li>Open Azure cloud shell</li>\n<li>Upload the <strong>task-kube-app.yaml</strong> file to cloud shell.  You can use the cloud shell menu or drag and drop the file onto cloud shell.</li>\n<li>Run the following command to load the AKS credentials:</li>\n</ul>\n<pre class=\"codehilite\"><code class=\"language-bash\">az aks get-credentials -n kubernetes -g 'task-kubernetes'</code></pre>\n\n<ul>\n<li>Run the following command to deploy the Kubernetes manifest:</li>\n</ul>\n<pre class=\"codehilite\"><code class=\"language-bash\">  kubectl apply -f ./task-kube-app.yaml</code></pre>\n\n<h2>Requirement 3: Verify the deployment</h2>\n<p>For this requirement you will monitor the kubernetes service to verify that the pods are running and that the service gets a public IP address.  You will then browse to the public IP address and confirm that you get the expected result.</p>\n<ul>\n<li>Verify that three pods are running:</li>\n</ul>\n<pre class=\"codehilite\"><code class=\"language-sh\">kubectl get pod</code></pre>\n\n<ul>\n<li>Verify that the service has a public IP address.  This may take a bit of time so the <strong>--watch</strong> option will update the output when the IP address is assigned.</li>\n</ul>\n<pre class=\"codehilite\"><code class=\"language-bash\">kubectl get service service-endpoint --watch</code></pre>\n\n<p><em>Note: Once the public IP shows up, press Ctrl-C to step watching.</em></p>\n<ul>\n<li>Open a browser tab and navigate to the public IP address of the service.</li>\n</ul>\n<p><em>Note: Refreshing the page should return a different result. Each pod (instance) is assigned a different host name and the service will \"round-robin\" between them.</em></p>\n<h2>Clean up</h2>\n<ul>\n<li>Delete the <strong>task-kubernetes</strong> resource group.</li>\n</ul>\n<p><em>Note: Other tasks use a virtual machine with Docker installed and this registry.  If you plan on completing other container related exercises, you may want to de-allocate the virtual machine rather than removing it, likewise you may not want to delete the registry yet.</em></p>\n<h2>Solution</h2>\n<p>Having trouble completing this task?  View the demonstration video to see how to do it.</p>",
    "tasks": "",
    "tasks_html": "",
    "published_date": "2020-05-23T04:34:28Z",
    "solutions": "",
    "solutions_html": "",
    "flags": [],
    "min_points_to_pass": null,
    "access_type": "default",
    "user_status": "unstarted",
    "user_lab_status": null,
    "user_status_modified": null,
    "user_flags": []
}