1 动手实战-基础学习之阿里云容器服务Kubernetes版快速入门
1.1 申请资源
1.2 再集群上创建应用
登陆后转到容器控制台
单击集群名称,转到容器管理界面,单击左边导航栏的工作负载后再单击无状态
单击使用镜像创建,再应用基本信息下面输入应用名称,如果浏览器放大倍数过大,上面的导航栏可能会纵向排列,这样会看不到输入应用信息的文本框,缩小以下浏览器的放大倍数使显示正常后输入应用名称(ack-cube),点击下一步,进入容器配置页面
复制粘贴镜像地址,填入资源限制,所需资源保持默认。向下滑动屏幕
填入容器名称及端口号,点击下一步进入高级配置
点击服务右边的创建连接
选择负载均衡,公网访问,新建SLB,服务端口和容器端口选择80,进入下一步,应用创建成功后显示下面界面。
1.3 访问应用
转到应用管理界面,点击详情
在本地浏览器上键入svc的外网地址,访问应用
1.4 容器和应用的监控
点击左侧导航看运维管理->prometheus监控
点击右边,
点击无状态应用监控,命名空间选择default,deployment选择ack-cube,pod选择all
点击右边V,
点击pod监控
也可以监控单独的pod
下面是这个应用的基本信息
2 动手实战-基础学习之Docker镜像管理快速入门
2.1 docker 安装
安装docker依赖库
[root@iZuf643m46s6kdj5ynchtbZ ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Installed: device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7_9.5 yum-utils.noarch 0:1.1.31-54.el7_8 Dependency Installed: device-mapper-event.x86_64 7:1.02.170-6.el7_9.5 device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5 libaio.x86_64 0:0.3.109-13.el7 libxml2-python.x86_64 0:2.9.1-6.el7_9.6 lvm2-libs.x86_64 7:2.02.187-6.el7_9.5 python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7 Dependency Updated: device-mapper.x86_64 7:1.02.170-6.el7_9.5 device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5 libxml2.x86_64 0:2.9.1-6.el7_9.6 Complete!
添加docker-ce yum仓库
[root@iZuf643m46s6kdj5ynchtbZ ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo Loaded plugins: fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
安装docker-ce
[root@iZuf643m46s6kdj5ynchtbZ ~]# yum makecache fast && > yum -y install docker-ce Installed: docker-ce.x86_64 3:20.10.12-3.el7 Dependency Installed: audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.4.12-3.1.el7 docker-ce-cli.x86_64 1:20.10.12-3.el7 docker-ce-rootless-extras.x86_64 0:20.10.12-3.el7 docker-scan-plugin.x86_64 0:0.12.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8 Dependency Updated: policycoreutils.x86_64 0:2.5-34.el7 Complete!
2.2 启动和配置docker加速
启动docker
[root@iZuf643m46s6kdj5ynchtbZ ~]# systemctl start docker
配置DokerHub镜像加速器
[root@iZuf643m46s6kdj5ynchtbZ ~]# tee /etc/docker/daemon.json <<-'EOF' > { > "registry-mirrors": ["https://registry.docker-cn.com"] > } > EOF { "registry-mirrors": ["https://registry.docker-cn.com"] }
重新启动docker
[root@iZuf643m46s6kdj5ynchtbZ ~]# systemctl restart docker
2.3 准备应用代码和Dockerfile
创建工作空间。
[root@iZuf643m46s6kdj5ynchtbZ ~]# mkdir -p /tmp/demo && cd /tmp/demo
在工作空间下创建HelloWorld代码文件,用来在容器环境中监听HTTP服务,输出HelloWorld字符串
[root@iZuf643m46s6kdj5ynchtbZ demo]# cat > /tmp/demo/main.go << EOF > package main > > import ( > "fmt" > "net/http" > ) > > func main() { > http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { > fmt.Fprintf(w, "Hello! World\n") > }) > > fmt.Println("start to serve...") > http.ListenAndServe(":80", nil) > } > EOF
创建dockfile
[root@iZuf643m46s6kdj5ynchtbZ demo]# cat > /tmp/demo/Dockerfile << EOF > FROM golang:1.12-alpine > > # change current working dir > WORKDIR /go/src/app > > # copy main.go into /go/src/app > COPY . . > > # go build and install the app > RUN go install -v ./... > > # run the app by default > CMD ["app"] > EOF
创建docke 映像
[root@iZuf643m46s6kdj5ynchtbZ demo]# docker build . -t demo:v1 Sending build context to Docker daemon 3.072kB Step 1/5 : FROM golang:1.12-alpine 1.12-alpine: Pulling from library/golang c9b1b535fdd9: Pull complete cbb0d8da1b30: Pull complete d909eff28200: Pull complete 665fbbf998e4: Pull complete 4985b1919860: Pull complete Digest: sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a Status: Downloaded newer image for golang:1.12-alpine ---> 76bddfb5e55e Step 2/5 : WORKDIR /go/src/app ---> Running in 50856c0618b9 Removing intermediate container 50856c0618b9 ---> 45abb87642ee Step 3/5 : COPY . . ---> e57146ac1ce7 Step 4/5 : RUN go install -v ./... ---> Running in c4efba75fe73 app Removing intermediate container c4efba75fe73 ---> fd90cbab2411 Step 5/5 : CMD ["app"] ---> Running in 4d98b944706f Removing intermediate container 4d98b944706f ---> ecfa6e962322 Successfully built ecfa6e962322 Successfully tagged demo:v1
创建并运行容器
[root@iZuf643m46s6kdj5ynchtbZ demo]# docker run -d -p 8000:80 demo:v1 9bbb45be7be18dd631de673ac4ff7085da0f57701d018b2c3c911c022e853f6e
检查容器运行效果
[root@iZuf643m46s6kdj5ynchtbZ demo]# curl localhost:8000
Hello! World
删除容器
[root@iZuf643m46s6kdj5ynchtbZ demo]# docker rm -f $(docker ps -a | grep "demo:v1" | awk '{print $1}')
9bbb45be7be1
2.4 创建远程镜像仓库
2.5 推送镜像
登陆远程仓库
[root@iZuf643m46s6kdj5ynchtbZ demo]# docker login --username=云深知何处lcx registry.cn-beijing.aliyuncs.com Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
标记镜像
[root@iZuf6gbozru2ddvscdru6uZ ~]#docker tag 216d652fb4f7 registry.cn-beijing.aliyuncs.com/my_study_2022/demo:v1
推送镜像
[root@iZuf6gbozru2ddvscdru6uZ ~]# docker push registry.cn-beijing.aliyuncs.com/my_study_2022/demo:v1 The push refers to repository [registry.cn-beijing.aliyuncs.com/my_study_2022/demo] 64ede27841c1: Pushed 6dc85406953e: Pushed bae429f8d06e: Pushed 7306dca01e79: Pushed 3957f7032fc4: Pushed 12c4e92b2d48: Pushed 45182158f5da: Pushed 5216338b40a7: Pushed v1: digest: sha256:4a2fc482d6f04d10948f7dcab3b41477f340a0eb8a5d9d783f080a3e724e1832 size: 1990
在远程仓库上查看
删除本地镜像后重新拉取镜像
[root@iZuf6gbozru2ddvscdru6uZ ~]# docker pull registry.cn-beijing.aliyuncs.com/my_study_2022/demo:v1 v1: Pulling from my_study_2022/demo c9b1b535fdd9: Already exists cbb0d8da1b30: Already exists d909eff28200: Already exists 665fbbf998e4: Already exists 4985b1919860: Already exists 60e753085483: Pull complete 6f2aab6ca296: Pull complete 1a5a87818da3: Pull complete Digest: sha256:4a2fc482d6f04d10948f7dcab3b41477f340a0eb8a5d9d783f080a3e724e1832 Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/my_study_2022/demo:v1 registry.cn-beijing.aliyuncs.com/my_study_2022/demo:v1 registry.cn-beijing.aliyuncs.com/my_study_2022/demo v1 216d652fb4f7 33 minutes ago 354MB golang 1.12-alpine 76bddfb5e55e 2 years ago 346MB
运行并检查检查容器
[root@iZuf6gbozru2ddvscdru6uZ ~]# docker run -d -p 8000:80 216d652fb4f7 e73356c523b711e59b0e26f6c85ae02971d5897f5205886cbbed61dfa5340eab [root@iZuf6gbozru2ddvscdru6uZ ~]# curl localhost:8000 Hello! World
3 进阶实战之Chaos带你快速上手混沌工程
3.1 申请资源
3.2 创建应用
查看集群
单击集群名称进入详情集群详情页
点击左侧导航栏的无状态
点击使用YAML创建资源
删除里面的模板,粘贴进去下面内容
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/nacos1.0.0 ports containerPort8848 env name PREFER_HOST_MODE value"hostname" name MODE value"standalone" resources limits cpu1 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 port8848 targetPort8848 --- apiVersion apps/v1 kind Deployment metadata name cart-redis spec selector matchLabels app cart-redis replicas1 template metadata labels app cart-redis spec containers name cart-redis image redis alpine imagePullPolicy IfNotPresent ports containerPort6379 resources limits cpu1 memory 512Mi requests cpu 200m memory 128Mi --- apiVersion v1 kind Service metadata labels app cart-redis name cart-redis spec ports port6379 targetPort6379 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/cartservice1.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 cpu1 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/recomendationservice1.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 cpu1 memory 512Mi requests cpu 200m memory 128Mi --- apiVersion apps/v1 kind Deployment metadata name product-mysql spec selector matchLabels app product-mysql replicas1 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 mysql5.6 name product-mysql ports containerPort3306 resources limits cpu1 memory 512Mi requests cpu 200m memory 128Mi --- apiVersion v1 kind Service metadata labels app product-mysql name product-mysql spec ports port3306 targetPort3306 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/productservice1.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 cpu1 memory 512Mi requests cpu 200m memory 128Mi --- apiVersion apps/v1 kind Deployment metadata name checkout-mysql spec selector matchLabels app checkout-mysql replicas1 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 mysql5.6 name checkout-mysql ports containerPort3306 resources limits cpu1 memory 512Mi requests cpu 200m memory 128Mi --- apiVersion v1 kind Service metadata labels app checkout-mysql name checkout-mysql spec ports port3306 targetPort3306 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 containerPort8080 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 cpu1 memory 512Mi requests cpu 200m memory 128Mi livenessProbe failureThreshold3 httpGet path /health port liveness-port scheme HTTP initialDelaySeconds5 periodSeconds10 successThreshold1 timeoutSeconds1 startupProbe failureThreshold3 httpGet path /health port liveness-port scheme HTTP initialDelaySeconds40 periodSeconds5 successThreshold1 --- 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 containerPort8080 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 cpu1 memory 512Mi requests cpu 200m memory 128Mi livenessProbe failureThreshold3 httpGet path /health port liveness-port scheme HTTP initialDelaySeconds5 periodSeconds10 successThreshold1 timeoutSeconds1 startupProbe failureThreshold3 httpGet path /health port liveness-port scheme HTTP initialDelaySeconds60 periodSeconds5 successThreshold1 --- apiVersion v1 kind Service metadata name frontend spec type ClusterIP selector app frontend ports name http port8080 targetPort8080 --- apiVersion v1 kind Service metadata name frontend-external spec type LoadBalancer selector app frontend ports name http port8080 targetPort8080
粘贴完毕后,点击创建。
点击frontend,进入其详情页
点击访问方式
点击frontend-external
点击外部端点
查看一个产品
添加到购物车
向下滑动屏幕
确认订单
3.3 部署高可用服务
回到集群列表
可能是版本的原因,这里和体验手册不同,点击应用市场
点击ack-ahas-pilot
点击一键部署
点击下一步
点击确定
3.4 应用高可用服务
架构感知
进入高可用服务控制台
点击架构感知
进入场景视图
点击kubenetes监控视图下的查看视图
点击确定
故障演练
成功创建了场景中的三个空白演练,演练效果也符合预期。这里也有版本的问题,导致在创建故障演练时下拉时找不到演练应用而无法选择应用,解决方法其实可以点击下图右边的找不到应用连接来找到
点击上面找不到应用的连接后,发现最终的解决办法需要在应用的yaml文件中加入app-instance及app-group标签,重新部署应用,在应用详情页可以找到更多操作-查看YAML
,在这里编辑以下,加入标签,重新部署应用,YAML要更改的部分可以参考下图
label标签下
ahas.aliyun/app-instance:frontend
ahas.aliyun/app-group:my_group
为新加部分,编辑完后点更新,重新部署这个应用。然后到创建故障演练界面里刷新即可找到应用。
自动演练场景,到这里就进行不下去了,一直找不到依赖关系。