k8s默认使用gcr.io做为镜像仓库,因为网络缘由没法正常访问,或者速度很是慢。我就使用了阿里云docker,来建立本身的私有仓库。html
阿里云docker管理界面地址node
使用阿里云加速访问docker hub。访问docker hub官方镜像时进行网络提速 docker
建立访问阿里云docker的secret对象,这里是阿里云docker的帐号密码api
ALI_DOCKER_REGISTRY_SERVER=https://registry.cn-hangzhou.aliyuncs.com/ ALI_DOCKER_USER=登录阿里云docker的用户名 ALI_DOCKER_EMAIL=登录阿里云docker的email ALI_DOCKER_PASSWORD=登录阿里云docker的密码 kubectl create secret docker-registry aliyun-docker \ --docker-server=$ALI_DOCKER_REGISTRY_SERVER \ --docker-username=$ALI_DOCKER_USER \ --docker-password=$ALI_DOCKER_PASSWORD \ --docker-email=$ALI_DOCKER_EMAIL
sudo docker pull node:10
以官方镜像为基础网络
先使用sudo docker images
,查看下载的node镜像id,app
而后打一个新的tag. sudo docker tag 5a401340b79f registry.cn-hangzhou.aliyuncs.com/xxxxx/node:10
curl
最后推送到本身的阿里云仓库 sudo docker push registry.cn-hangzhou.aliyuncs.com/xxxxx/node:10
post
若是是私有仓库,要保证已经docker登陆了阿里云帐号,不然没法推送ui
应用dockerfile内容以下阿里云
FROM registry.cn-hangzhou.aliyuncs.com/xxxxx/node:10 EXPOSE 8080 COPY server.js . CMD node server.js
应用server.js内容以下
var http = require('http'); var handleRequest = function(request, response) { console.log('Received request for URL: ' + request.url); response.writeHead(200); response.end('Hello World!'); }; var www = http.createServer(handleRequest); www.listen(8080);
构建应用镜像
sudo docker build --tag registry.cn-hangzhou.aliyuncs.com/xxxxx/hello_world:v0.1 ./
上传到阿里云仓库
sudo docker push registry.cn-hangzhou.aliyuncs.com/xxxxx/hello_world:v0.1
pod的yaml内容以下:
apiVersion: v1 kind: Pod metadata: name: helloworld labels: app: helloworld spec: containers: - name: helloworld image: registry.cn-hangzhou.aliyuncs.com/xxxxx/hello_world:v0.1 imagePullPolicy: Always ports: - containerPort: 8080 imagePullSecrets: - name: aliyun-docker
建立pod,sudo kubectl apply -f helloworld.yaml
经过sudo kebectl describe pod helloworld
,获得pod的状态和运行在哪一个node,以及pod的容器ip。
在部署的node上,curl http://pod容器IP:8080
访问,输出 hello world
sudo kubectl describe pod helloworld
查看pod的状态以及建立过程等信息
sudo kubect get no -o yaml
或者
sudo kubectl describe node xxx
查看node的健康检查等信息