第四期:零基础容器技术实战

Chaos带你快速上手混沌工程

1. 创建实验资源

在页面左侧,单击云产品资源下拉菜单,查看本次实验资源。
单击免费开通创建所需资源。
说明:

资源创建过程需要1~3分钟。完成实验资源的创建后,您可以在云产品资源列表查看已创建的资源信息,例如:IP地址、用户名和密码等。

2. 创建应用

  1. 点击右侧 图标,切换到远程桌面操作界面。
  2. 双击打开虚拟桌面的Firefox ESR浏览器,在RAM用户登录框中点击“下一步”,复制云产品资源列表中子用户密码,粘按CTRL+V把密码粘贴到密码输区,登陆子账户(后续在远程桌面里的粘贴操作均使用CTRL + V快捷键)。
  3. 复制容器服务ACK控制台地址,在FireFox浏览器打开新页签,粘贴并访问容器服务ACK控制台。
https://cs.console.aliyun.com/
  1. 在集群页面,单击详情。

第四期:零基础容器技术实战

  1. 在左侧导航栏,单击无状态。

第四期:零基础容器技术实战

  1. 在无状态页面,单击使用YAML创建资源。

第四期:零基础容器技术实战

  1. 在创建页面,复制以下代码并粘贴到模板框中,然后单击创建。
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nacos-server
spec:
  selector:
    matchLabels:
      app: nacos-server
  template:
    metadata:
      labels:
        app: nacos-server
    spec:
      containers:
        - name: nacos-standalone
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/nacos:1.0.0
          ports:
            - containerPort: 8848
          env:
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: MODE
              value: "standalone"
          resources:
            limits:
              cpu: 1
              memory: 2048Mi
            requests:
              cpu: 200m
              memory: 512Mi
---

apiVersion: v1
kind: Service
metadata:
  name: nacos-server
spec:
  type: ClusterIP
  selector:
    app: nacos-server
  ports:
    - name: http
      port: 8848
      targetPort: 8848
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cart-redis
spec:
  selector:
    matchLabels:
      app: cart-redis
  replicas: 1
  template:
    metadata:
      labels:
        app: cart-redis
    spec:
      containers:
        - name: cart-redis
          image: redis:alpine
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 6379
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: cart-redis
  name: cart-redis
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: cart-redis
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cartservice
spec:
  selector:
    matchLabels:
      app: cartservice
  template:
    metadata:
      labels:
        app: cartservice
    spec:
      containers:
        - name: cartservice
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/cartservice:1.0.0
          imagePullPolicy: Always
          env:
            - name: dubbo.registry.address
              value: "nacos://nacos-server:8848"
            - name: spring.cloud.nacos.discovery.server-addr
              value: "nacos-server:8848"
            - name: spring.cloud.nacos.config.server-addr
              value: "nacos-server:8848"
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: recommendationservice
spec:
  selector:
    matchLabels:
      app: recommendationservice
  template:
    metadata:
      labels:
        app: recommendationservice
        version: 1.0.0-SNAPSHOT
    spec:
      containers:
        - name: recommendationservice
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/recomendationservice:1.0.0
          # imagePullPolicy: Always
          env:
            - name: dubbo.registry.address
              value: "nacos://nacos-server:8848"
            - name: spring.cloud.nacos.discovery.server-addr
              value: "nacos-server:8848"
            - name: spring.cloud.nacos.config.server-addr
              value: "nacos-server:8848"
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-mysql
spec:
  selector:
    matchLabels:
      app: product-mysql
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: product-mysql
    spec:
      containers:
        - args:
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_unicode_ci
          env:
            - name: MYSQL_DATABASE
              value: product
            - name: MYSQL_ROOT_PASSWORD
              value: productservice
          image: mysql:5.6
          name: product-mysql
          ports:
            - containerPort: 3306
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: product-mysql
  name: product-mysql
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    app: product-mysql
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: productservice
spec:
  selector:
    matchLabels:
      app: productservice
  template:
    metadata:
      labels:
        app: productservice
        version: 1.0.0-SNAPSHOT
    spec:
      containers:
        - name: productservice
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/productservice:1.0.0
          imagePullPolicy: Always
          env:
            - name: dubbo.registry.address
              value: "nacos://nacos-server:8848"
            - name: spring.cloud.nacos.discovery.server-addr
              value: "nacos-server:8848"
            - name: spring.cloud.nacos.config.server-addr
              value: "nacos-server:8848"
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: checkout-mysql
spec:
  selector:
    matchLabels:
      app: checkout-mysql
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: checkout-mysql
    spec:
      containers:
        - args:
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_unicode_ci
          env:
            - name: MYSQL_DATABASE
              value: checkout
            - name: MYSQL_ROOT_PASSWORD
              value: checkoutservice
          image: mysql:5.6
          name: checkout-mysql
          ports:
            - containerPort: 3306
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: checkout-mysql
  name: checkout-mysql
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    app: checkout-mysql
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: checkoutservice
spec:
  selector:
    matchLabels:
      app: checkoutservice
  template:
    metadata:
      labels:
        app: checkoutservice
    spec:
      containers:
        - name: checkoutservice
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/checkoutservice:health
          imagePullPolicy: Always
          ports:
            - name: liveness-port
              containerPort: 8080
              protocol: TCP
          env:
            - name: dubbo.registry.address
              value: "nacos://nacos-server:8848"
            - name: spring.cloud.nacos.discovery.server-addr
              value: "nacos-server:8848"
            - name: spring.cloud.nacos.config.server-addr
              value: "nacos-server:8848"
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          startupProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 40
            periodSeconds: 5
            successThreshold: 1

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
        - name: frontend
          image: registry.cn-beijing.aliyuncs.com/ahas_demo/frontend:async-test
          imagePullPolicy: Always
          ports:
            - name: liveness-port
              containerPort: 8080
              protocol: TCP
          env:
            - name: dubbo.registry.address
              value: "nacos://nacos-server:8848"
            - name: spring.cloud.nacos.discovery.server-addr
              value: "nacos-server:8848"
            - name: spring.cloud.nacos.config.server-addr
              value: "nacos-server:8848"
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 128Mi
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          startupProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 60
            periodSeconds: 5
            successThreshold: 1
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  type: ClusterIP
  selector:
    app: frontend
  ports:
    - name: http
      port: 8080
      targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: frontend-external
spec:
  type: LoadBalancer
  selector:
    app: frontend
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  1. 在左侧导航栏,单击无状态。
  2. 在无状态页面,等待几分钟,单击刷新,容器组数量全部为1/1之后,表示应用部署完成。

3. 安装探针

  1. 回到容器服务控制台页面,单击左侧导航栏上方的 图标。
  2. 在集群列表页面的左侧导航栏中,单击应用目录。
  3. 在应用目录页面,单击ack-ahas-pilot。
  4. 在ack-ahas-pilot的详情页面,单击创建。

4. 通过架构感知查看系统整体架构

  1. 复制应用高可用服务控制台地址,在Firefox浏览器打开新页签,粘贴并访问容器服务应用高可用服务控制台。
https://chaos.console.aliyun.com/
  1. 在概览页面顶部,选择资源所在地域。例如下图中,地域切换为华东1(杭州)。
  2. 在左侧导航栏,单击故障演练>架构感知。
  3. 在架构地图页面,单击Kubernetes监控视图卡片中的查看视图。
  4. 在架构地图页面,打开Kubernetes监控视图下拉列表,选择命令空间为default,然后单击确定即可查看实验资源的Kubernetes监控视图。
上一篇:为什么不使用ZooKeeper构建云平台发现服务?


下一篇:《嵌入式 Linux应用程序开发标准教程(第2版)》——第2章 Linux基础命令