尝试运行 Microsoft Azure 上的 Kubernetes 投票应用程序

YAML的中文:YAML格式

apiVersion: v1
kind: Namespace
metadata:
  name: vote-app
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deploy
  namespace: vote-app
spec:
  selector:
    matchLabels:
      app: redis-deploy
  template:
    metadata:
      labels:
        app: redis-deploy
    spec:
      containers:
        - name: redis-deploy
          image: redis
          resources:
            limits:
              memory: "128Mi"
              cpu: "100m"
          ports:
            - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  name: redis-svc
  namespace: vote-app
spec:
  selector:
    app: redis-deploy
  ports:
    - port: 6379
      targetPort: 6379
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vote-deploy
  namespace: vote-app
spec:
  selector:
    matchLabels:
      app: vote-deploy
  template:
    metadata:
      labels:
        app: vote-deploy
    spec:
      containers:
        - name: vote-deploy
          image: microsoft/azure-vote-front:v1
          resources:
            limits:
              memory: "128Mi"
              cpu: "100m"
          ports:
            - containerPort: 80
          env:
            - name: REDIS
              value: "redis-svc"
---
apiVersion: v1
kind: Service
metadata:
  name: vote-svc
  namespace: vote-app
spec:
  type: LoadBalancer
  selector:
    app: vote-deploy
  ports:
    - port: 80
      targetPort: 80

投入 rù)

$ kubectl apply -f .
namespace/vote-app created
deployment.apps/redis-deploy created
service/redis-svc created
deployment.apps/vote-deploy created
service/vote-svc created

确认操作

$ kubectl get svc -n vote-app
NAME        TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE     SELECTOR
redis-svc   ClusterIP      10.98.237.27   <none>        6379/TCP       3m25s   app=redis-deploy
vote-svc    LoadBalancer   10.96.230.52   10.0.0.200    80:31102/TCP   3m25s   app=vote-deploy

因为选择了负载均衡器,所以请访问显示的 IP 地址(EXTERNAL-IP)。

image.png

我确认它正常运行了。

bannerAds