如何在微软文档的Kubernetes示例YAML配置中切换GitHub仓库?
Hey there! I get it, swapping out the GitHub repo behind your Azure Vote deployment can feel a bit tricky at first, but let's walk through exactly what you need to do.
First, a quick clarification: The YAML you shared uses pre-built container images from Microsoft's registry. To use your own GitHub repo's code, you'll first need to build your code into a container image (using a Dockerfile, which is typically included in the Azure Vote sample repos) and push that image to a container registry like Azure Container Registry (ACR) or Docker Hub. Once that's done, you'll update the image field in your YAML to point to your custom image.
Exact Modification Paths in Your YAML
Here are the specific spots to update:
1. For the Frontend (azure-vote-front Deployment)
Look for the azure-vote-front Deployment section, find the containers block, and replace the existing image value with your custom image URL:
# Original line image: mcr.microsoft.com/azuredocs/azure-vote-front:v1 # Replace with your image, e.g.: image: your-acr-registry.azurecr.io/your-custom-azure-vote-front:latest
2. For the Backend (If You're Customizing Redis)
If you're also using a custom Redis image from your GitHub repo, update the image field in the azure-vote-back Deployment section:
# Original line image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 # Replace with your custom Redis image URL image: your-registry.io/your-custom-redis:v1
Important Notes
- Image Pull Access: If your container registry is private, you'll need to create an
ImagePullSecretin your Kubernetes cluster and reference it in thespec.imagePullSecretsfield of each Deployment. This lets K8s authenticate and pull your private images. - Environment Variables: If your custom code requires different environment variables (e.g., a different Redis connection string), adjust the
envblocks in the Deployment sections to match your app's needs. The currentREDISvariable pointing toazure-vote-backworks because that's the name of the backend Service—you only need to change this if you rename the backend Service.
Example Modified Frontend Deployment Snippet
Here's how your updated azure-vote-front Deployment might look:
apiVersion: apps/v1 kind: Deployment metadata: name: azure-vote-front spec: replicas: 1 selector: matchLabels: app: azure-vote-front template: metadata: labels: app: azure-vote-front spec: nodeSelector: "kubernetes.io/os": linux # Optional: Add image pull secret if using private registry # imagePullSecrets: # - name: your-registry-secret containers: - name: azure-vote-front image: your-acr-name.azurecr.io/custom-azure-vote-front:v2 resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi ports: - containerPort: 80 env: - name: REDIS value: "azure-vote-back"
内容的提问来源于stack exchange,提问作者user770022

