learn.udacity.com/courses/ud6… 主要四部分,微服务,docker,kubernates,developments 大约三小时,快速的了解是什么干什么简单使用 深入了解/操作看肯定还是去看官方文档
Microservace
介绍微服务,搞了个谷歌云的例子,需要visa卡,就不实操了,看看命令 12 factor app 12factor.net/zh_cn/logs 一些微服务/大型程序设计原则 json web token jwt.io/ 可以解码 用户发起请求验证,就请用户自己保存token docker kubernates都是为了微服务设计/12 factor设计的目的,快速插拔,可扩展,可移植性等等,而诞生的自动化管理工具
DOCKER
Here are more resources describing Docker: Understand how Docker works and how you can use it - www.docker.com/what-docker Introduction to Docker - opensource.com/resources/w…
Here are two articles with a good write-ups about containers, if you want to go more in-depth about container technology www.computerworld.com/article/269…
github.com/moby/moby/b… docker的随机命名,不无聊的steve
【docker常用命令】
docker ps -aq q:quite(linux,ps会显示有哪些进程和一些相关信息,aq只会显示id)
<https://news.ycombinator.com/item?id=11000827>
<https://hub.docker.com/_/alpine/>
【插播一下awk】有工具有语言,可以awk文件也可以awk语句,文件记得chmod+x 文件
【dokerfile】
#注释\
from 定义源(常用alpine)
MAINTAINER 维护者
ADD hello usr/xxx把主机一个文件夹加到image目录下
ENTRYPOINT 入口程序
VOLUME 你记得么,文件生成到外面
If you are tired of typing "sudo" in front of all Docker commands, and confused why a lot of examples don't have that, please read the following article about implications on security - Why we don't let non-root users run Docker in CentOS, Fedora, or RHEL
<https://projectatomic.io/blog/2015/08/why-we-dont-let-non-root-users-run-docker-in-centos-fedora-or-rhel/>
【】CID2=$(sudo docker run -d auth:1.0.0) 是一个Shell命令,用于在Docker中运行一个容器,并将容器的ID赋值给变量 CID2,一边后续使用id
【Registries】
Docker Hub 是我们在此类中使用的注册表。注册 docker 中心并创建一个存储库 <<https://hub.docker.com/或https://quay.io/> 或大企业可以选[https://cloud.google.com/container-registry/docs/>](https://cloud.google.com/container-registry/docs/>)
A write up comparing some of the different registries: <http://rancher.com/comparing-four-hosted-docker-registries/>
ADD TAG sudo docker tag monolith:1.0.0 <your username>/monolith:1.0.0
PUSH sudo docker login
sudo docker push udacity/example-monolith:1.0.0
kubernates
主要有以下四个功能 APP CONFIGURATION SERVICE DISCOVERY MANAGING UPDATES MONITORING
【命令】To help out, here’s a Kubernetes command cheat sheet. kubernetes.io/docs/user-g… Launch a single instance: kubectl run nginx --image=nginx:1.10.0 Get pods kubectl get pods Expose nginx kubectl expose deployment nginx --port 80 --type LoadBalancer List services kubectl get services
【Pod】kubernetes.io/docs/user-g…是一个logical application ,包括一个或多个container 和volume。共享namespace,所以同一个ip
【命令】kubectl get pods还可以get其他的 比如replicasets
kubectl describe pods monolith
kubectl port-forward monolith 10080:80 吧monolith 容器监听80映射到外部ip的10080
kubectl logs monolith
kubectl exec monolith --stdin --tty -c monolith /bin/sh在pod里启动shell交互 exit退出
【MHC】monitoring and health checking-kubernetes.io/docs/user-g… pod里的kubelets负责,pod里面有container和kubelets,container里面有app,有时container还好但app停了
kubelets是问container的 kubernetes.io/docs/concep…
readiness probe 就绪探测
cat pods/healthy-monolith.yaml
kubectl describe pods healthy-monolith
【configeration】存储配置和一些证书,不要打包到docker里,不要放到pod里 使用:configmap和secret
kubectl create secret generic tls-certs --from-file=tls/
kubectl describe tls-certs
kubectl create -f pods/secure-monolith.yaml 把secret当作一个volume装载到pod
kubectl create configmap nginx-proxy-conf --from-file=nginx/proxy.conf
cat pods/secure-monolith.yaml
"lifecycle:
preStop:
exec:
command:\["/usr/sbin/nginx","-s","quit"]"可以用这种方式关闭
volume也在yaml文件里会提到,因为tsl要用。这些都是上面两个使用kubectl命令后会自动添加的
【services】可以根据label自动连接启动的pod分配固定端口以向外提供服务,可以帮助负载均衡--kubernetes.io/docs/user-g…
kubectl create -f services/secure-monolith.yaml
cat services/monolith.yaml 可以看到selector里有app名,可以通过这个连接pod
再次注:ports里面targetPort是外面的,nodePort是里面的
Deploying Microservices
【depolyment】资源对象,用于定义和管理应用程序的部署。Deployments提供了一种声明性的方式来描述应用程序的期望状态,并确保系统按照所定义的状态进行部署和维护。
cat deployments/yourapp.yaml replicas
kubectl create -f deployments/auth.yaml
kubectl describe deployments auth
【Scaling】支持修改配置比如副本数并apply
kubectl get pods -1 "app=hello,track=stable"
vi deployments/hello.yaml
kubectl apply -f deployments/hello.yaml
【Updating】更新时不要一次对所有都更新 queue CTO roll out,逐步替换
vi deployments/hello.yaml spec:container:image:修改版本号
kubectl apply -f deployments/hello.yaml
kubectl describe deployments hello可以看NewReplicaSet,里面有替换信息
kubectl get pods
kubectl describe pods podname可以看到类似yaml里面的名字和版本号
总结
了解了为什么docker和kubernates,docker的一些基本配置dockerfile,kubernates基础配置基础命令:get/describe/log/exec/create(secret or configmap),pod、deployments、services文件夹下有相关信息(很像linux)