kubernetes_on_macOS

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there’s output, you’re good!

Prerequisites

  • kubectl
  • docker (for Mac)
  • minikube
  • virtualbox
brew update && brew install kubectl && brew cask install docker minikube virtualbox

Verify

docker --version                # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version        # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version        # docker-machine version 0.12.2, build 9371605
minikube version                # minikube version: v0.22.3
kubectl version --client        # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"}      

Start

minikube start

This can take a while, expected output:

Starting local Kubernetes cluster...
Kubectl is now configured to use the cluster.

Great! You now have a running Kubernetes cluster locally. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.

Check k8s

kubectl get nodes

Should output something like:

NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready     <none>    40s       v1.7.5

Use minikube’s built-in docker daemon:

eval $(minikube docker-env)

Running docker ps should now output something like:

CONTAINER ID        IMAGE                                         COMMAND                 CREATED             STATUS              PORTS               NAMES
e97128790bf9        gcr.io/google-containers/kube-addon-manager   "/opt/kube-addons.sh"   22 seconds ago      Up 22 seconds                           k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0
69707e54d1d0        gcr.io/google_containers/pause-amd64:3.0      "/pause"                33 seconds ago      Up 33 seconds                           k8s_POD_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0

Build, deploy and run an image on your local k8s setup

First setup a local registry, so Kubernetes can pull the image(s) from there:

docker run -d -p 5000:5000 --restart=always --name registry registry:2

Build

First of, store all files (Dockerfile, my-app.yml, index.html) in this gist locally in some new (empty) directory.

You can build the Dockerfile below locally if you want to follow this guide to the letter. Store the Dockerfile locally, preferably in an empty directory and run:

docker build . --tag my-app

You should now have an image named ‘my-app’ locally, check by using docker images (or your own image of course). You can then publish it to your local docker registry:

docker tag my-app localhost:5000/my-app:0.1.0

Running docker images should now output the following:

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
my-app                                                 latest              cc949ad8c8d3        44 seconds ago      89.3MB
localhost:5000/my-app                                  0.1.0               cc949ad8c8d3        44 seconds ago      89.3MB
httpd                                                  2.4-alpine          fe26194c0b94        7 days ago          89.3MB

Deploy and run

Store the file below my-app.yml on your system and run the following:

kubectl create -f my-app.yml

You should now see your pod and your service:

kubectl get all

The configuration exposes my-app outside of the cluster, you can get the address to access it by running:

minikube service my-app --url

This should give an output like http://192.168.99.100:30304 (the port will most likely differ). Go there with your favorite browser, you should see “Hello world!”. You just accessed your application from outside of your local Kubernetes cluster!

Kubernetes GUI

minikube dashboard

Delete deployment of my-app

kubectl delete deploy my-app
kubectl delete service my-app

You’re now good to go and deploy other images!

Reset everything

minikube stop;
minikube delete;
rm -rf ~/.minikube .kube;
brew uninstall kubectl;
brew cask uninstall docker virtualbox minikube;

TODO

Will try to convert this to xhyve when possible.

Version

Last tested on 2017 October 20th macOS Sierra 10.12.6

淘宝 TAE2.0(Taobao App Engine)

TAE2.0(Taobao App Engine)是针对移动互联网场景的定制化PaaS云服务,基于阿里云基础设施,采用Docker容器技术封装应用运行环境,并且针对互联网应用提供系统构建、发布、持续集成、运维管理的一站式解决方案,让中小团队也具备轻松服务海量用户的能力。

系统构建能力(Build)

TAE拥有丰富的镜像资源,例如Java、PHP、MySQL、Redis、Zookeeper等镜像;开发者可以利用官方镜像,快速搭建系统,完成在TAE2.0上的架构搭建;若官方镜像无法覆盖架构需求,则开发者可利用自定义镜像轻松搭建系统。

通过镜像创建容器:

图片描述

构建自定义镜像:

图片描述

官方镜像 :TAE提供丰富的官方镜像,供开发者创建各种类型的服务。除了 Java、PHP、Python三种Web服务器镜像外,还提供了其他常用镜像,如存储(MySQL、MongoDB)、缓存(Redis、Memcached)、消息队列(ActiveMQ、RabbitMQ)、大数据计算(Hadoop)、代理服务器(Nginx)、分布式框架(Dubbo、ZooKeeper),内容管理(Wordpress)等。开发者通过选择镜像可以一键部署相应的服务,轻松搭建起自己的整套架构。

自定义镜像: 如果官方提供的镜像不能满足需求,TAE还支持开发者构建自定义Docker镜像,通过自定义Docker镜像开发者可以创建高度个性化的服务,比如各类语言的运行环境(如:ruby、go、node.js等)、各类服务器软件Apache、Lighttpd等等。TAE支持两种构建自定义镜像方式:在线制作自定义镜像、本地制作镜像制作并提交TAE私有仓库。

公共镜像加速:

Docker registry在中国既没有部署服务器也没有CDN加速节点,造成国内开发者从Docker registry下载镜像效率低下,TAE利用自身的遍布全国的CDN网络,为开发者提供Docker registry的下载加速服务。

应用部署能力(Deploy)

互联网创业项目一般具有周期短、业务爆发快等特点,这使得应用的发布升级非常频繁,TAE提供完善的开发工具和部署发布系统,提升开发部署效率,保障应用平滑发布。

图片描述

发布管理系统 :

— 部署发布

根据不同的使用场景和开发习惯,TAE提供了多种部署发布手段:

1.上传部署

开发者在本地将程序编译打包好后,上传到服务的测试环境,上传完毕后TAE将自动执行部署。

2.编译部署

开发者使用代码仓库管理应用的源代码,可以通过指定代码仓库分支直接编译部署到测试环境。

3.回滚部署

开发者每次部署的程序包会自动备份到历史版本,发布异常时,可以指定回滚部署到某一历史版本。

4.Beta发布

发布新版本的程序时,可以选择正式环境中的部分实例进行发布,而其它实例保留运行老版本程序,新版本运行一段时间无异常后,再全部上线,以确保发布稳定 。

线上-测试环境模式

针对应用服务器类的服务,提供了线上环境和测试环境两个运行环境,开发者可以先在测试环境部署验证通过后,再上线到正式环境,确保发布稳定。

主-备环境模式

对于支持主-备部署的服务(如MongoDB、Redis等),支持创建Master和Slave两套运行环境,默认master提供线上服务,一旦Master发生问题,开发者可以将slave切换为Master,以保障线上服务稳定。

在线IDE :支持单文件热部署以及整体应用的打包部署;支持在线编辑代码、推送仓库等操作。

运维管理能力(Management)

据统计,70%的移动互联网应用都曾遭受网络攻击而导致故障,创业团队往往难以应对,TAE提供了多重的安全防护机制,让系统免受基础设施故障和网络攻击的困扰。

同时,互联网创业团队一般规模较小、资源有限,应用的日常运维工作又耗时耗力,开发专业运维系统又成本高昂,TAE集成了运行环境管理、数据库管理、自动化监控、日志采集分析、压测系统,将开发者从运维工作中解放出来,专注业务实现。

图片描述

运行环境安全 :应用运行环境数据采用多重备份,并且实现了自动恢复的策略,服务可用性达到99.95%。网络方面采用了硬件防火墙设施,提供四层到七层的全面防护,防护类型包括CC、SYN flood、UDP flood等所有DDoS攻击方式,支持清洗和黑洞机制,还接入了waf防护等功能。

运行环境管理:

弹性管理

当业务面临突发增长或下降时,开发者可以根据需要对服务的运行实例个数进行调整,TAE会自动完成新增实例的生产、部署和接入负载均衡器进行分流。弹性扩缩过程完全平滑,用户无感知。

SSH登录容器

对于运行中的实例(容器),开发者可以使用TAE提供的Webssh或SSH客户端工具直接登录到Docker容器进行管理,提供linux服务器的原生管理体验。

配置管理

TAE支持对服务的运行环境进行配置修改,对于包括网络接入、日志采集路径、环境变量、高级配置(主要是“网络模式”和“状态模式”)的配置进行修改。

数据库管理系统:

RDS控制台

对于TAE官方的RDS服务,开发者可以使用RDS控制台对数据库进行日常管理,支持导入SQL文件、数据库备份、数据库连接管理、数据库参数设置、重启实例等功能。

iDB工具

对于TAE官方的RDS服务和通过镜像创建的MySQL服务,还提供阿里自主研发的iDB管理工具,支持对数据库表结构、数据内容、日志进行透出和管理,并提供对实例会话、事务锁、数据库服务器性能等的监控。

监控系统:

针对应用和数据库,提供针对关键性能指标的实时监控和告警,提高系统日常运维效率。

应用监控

提供QPS(每秒查询率)、RT(请求响应时间)、PV(页面浏览量)、CPU使用率、访问错误码、自定义URL、日志关键字、应用所使用的数据源性能等进行监控。

RDS监控

提供连接数、存储空间、IOPS(每秒进行读写I/O操作的次数)、QPS(每秒查询率)、每秒SQL执行数、慢SQL、网络流量等指标的监控。

日志系统:

查询日志

提供日志自动采集和分析,支持对应用日志、访问日志进行格式化展示,支持包括错误码分析、URI日志分析、关键字筛查、慢日志分析在内的多种查询分析手段。

实时日志

支持日志的实时输出展示,为开发者排查问题提供强有力支持。

在线诊断工具:

TAE为Java开发者提供了Jstack分析工具,为php开发者提供了xhprof工具,支持开发者进行在线的性能问题排查。

压测系统:

服务端程序的自动化压测和分析工具,开发者提交测试任务后,系统自动对应用进行施压并搜集性能表现指标,并输出测试报告,帮助开发者诊断性能瓶颈。

权限管理系统:

对于团队作业的开发者,TAE提供针对控制台和代码仓库的分权管理体系,解决不同角色的开发者分工协作的问题,支持子账号创建,角色管理、权限分配等功能。

使用docker命令时,如何避免使用sudo

在我们使用docker的时候,想查看docker下都有哪些镜像,执行命令:

  1. docker images

可结果却给了我们这样的提示:

  1. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.29/images/json: dial unix /var/run/docker.sock: connect: permission denied

告诉我们没有权限,我们就必须在命令前加上sudo,但是这样的话,我们操作docker的时候也太麻烦了,所以我们要想办法去掉这个sudo。

我们拒绝不知所以然的拿来主义,所以要在拿来之后深究一下为什么。

上面说道,连接/var/run/docker.sock的时候,由于没有权限,被拒绝访问了,那么,我们去看一下这个文件的所有者和所属组是什么。

执行:

  1. sudo ls l /var/run/docker.sock

结果显示:

  1. srwrw—- 1 root docker 0 Jul 12 22:41 /var/run/docker.sock

我们看到docker.sock是属于root用户和docker组的,我们使用的用户既不是root也不在docker组。那么问题应该就好解决了,所有者咱不动,因为不知道动了以后会有什么问题,我们把当前登录用户加入到docker组就可以了,执行:

  1. sudo gpasswd a ${USER} docker

这样就加入到了用户组,但是此时group命令获取到的是缓存组的信息,我们执行docker images的话,仍然会报错,我们需要手动切换一次组:

  1. newgrp docker

再次执行:

  1. docker images

Maven常用插件

=========Maven Report Plugin=========
1.源码分析

<artifactId>maven-pmd-plugin</artifactId>

2.代码格式检查

<artifactId>maven-checkstyle-plugin</artifactId>

3.代码相似度检查

<groupId>org.codehaus.mojo</groupId>
<artifactId>simian-maven-plugin</artifactId>

4.格式化统计报告

<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>

5.FireBug检查

<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>

6.JavaDoc

<artifactId>maven-javadoc-plugin</artifactId>

7.生成java代码交叉引用和源代码的html格式

<artifactId>maven-jxr-plugin</artifactId>

8.代码覆盖率

<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>

<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>

9.java代码的度量工具

<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>

10.单元测试报告

<artifactId>maven-surefire-report-plugin</artifactId>

11.TODO检查报告

<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>

12.项目总报告

<artifactId>maven-project-info-reports-plugin</artifactId>

 

=========Maven Common Plugin=========
1.SCP文件传输

<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>

2.SSH命令

<groupId>com.github.goldin</groupId>
<artifactId>sshexec-maven-plugin</artifactId>

3.Maven Job

<groupId>com.github.goldin</groupId>
<artifactId>jenkins-maven-plugin</artifactId>

4.生成about信息

<groupId>com.github.goldin</groupId>
<artifactId>about-maven-plugin</artifactId>

5.查找重复依赖

<groupId>com.github.goldin</groupId>
<artifactId>duplicates-finder-plugin</artifactId>

6.Maven邮件发送

<groupId>com.github.goldin</groupId>
<artifactId>mail-maven-plugin</artifactId>

7.项目目录查找

<groupId>com.github.goldin</groupId>
<artifactId>find-maven-plugin</artifactId>

8.获取SVN版本

<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>maven-svn-revision-number-plugin</artifactId>

9.编译C++

<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>

10.DDL生成

<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>

11.Eclipse RCP

<groupid>org.sonatype.tycho</groupid>
<artifactid>target-platform-configuration</artifactid>

 

=========Maven Official Plugin=========
1.自动定义打包

<artifactId>maven-assembly-plugin</artifactId>

2.ANT

<artifactId>maven-antrun-plugin</artifactId>

 

=========Maven 全局属性=========
1.源码编码

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
maven.compile.classpath
maven.runtime.classpath
maven.test.classpath
maven.plugin.classpath

2.ClassPath

maven.compile.classpath
maven.runtime.classpath
maven.test.classpath
maven.plugin.classpath