KubernetesUpAndRunning-Containers
来源:互联网 发布:ping值测试软件 编辑:程序博客网 时间:2024/05/16 18:49
Container images are typically combined with a container configuration file, which provides instructions on how to setup the container environment and execute an application entrypoint
.
System Containers
System containers seek to mimic virtual machines and often run a full boot process.
Application Containers
Application containers differ from system containers in that they commonly run a single application.
Building Application Images with Docker
A Dockerfile
can be used to automate the creation of a Docker container image.
FROM scratch # The scratch base image does not take any space.MAINTAINER Kelsey Hightower <kelsey.hightower@kuar.io>COPY influxd /influxdENTRYPOINT ["/influxd"]
Run the following command to create the influxdb Docker image:
$ docker build -t influxdb:0.9.4.2 .
Storing Images in a Remote Registry
First I authenticated to the Google Container Registry using gcloud:
$ gcloud docker --authorize-only
Next I tagged the influxdb image by prepending the target Docker registry:
$ docker tag influxdb:0.9.4.2 b.gcr.io/kuar/influxdb:0.9.4.2
Then I pushed the influxdb image:
$ docker push b.gcr.io/kuar/influxdb:0.9.4.2
To make all images in this bucket public I ran the following command:
gsutil -m acl ch -R -u AllUsers:R gs://kuar
Running Containers with Docker
To deploy a container from the b.gcr.io/kuar/influxdb:0.9.4.2 image run the following command:
$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ b.gcr.io/kuar/influxdb:0.9.4.2
The above command starts the influxdb database and maps ports 38083 to 8083 and 38086 to 8086. This will allow us to access influxdb on the host IP address. The ability to map high level ports to containers helps avoid port conflicts. Each container gets its own IP address assigned by Docker.
Exporing the influxdb API
$ curl -G 'http://localhost:38086/query' \ --data-urlencode "q=CREATE DATABASE kubernetes"
Output:
{"results":[{}]}
Now lets add some test data to the kubernetes database:
$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node0 count=10'$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node1 count=9'$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node2 count=12'
Run the following command to get the sum of all pod counts stored in the kuberentes test database:
$ curl -G http://localhost:38086/query?pretty=true \ --data-urlencode "db=kubernetes" \ --data-urlencode "q=SELECT SUM(count) FROM pod"
Output:
{ "results": [ { "series": [ { "name": "pod", "columns": [ "time", "sum" ], "values": [ [ "1970-01-01T00:00:00Z", 31 ] ] } ] } ]}
Limiting Resource Usage
LIMITING MEMORY RESOURCES
Stop and remove the current influxdb container:
$ docker stop influxdb$ docker rm influxdb
Then start another influxdb container using the appropriate flags to limit memory usage:
$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ --memory 200m \ --memory-swap 1G \ b.gcr.io/kuar/influxdb:0.9.4.2
LIMITING CPU RESOURCES
$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ --memory 200m \ --memory-swap 1G \ --cpu-shares 1024 \ b.gcr.io/kuar/influxdb:0.9.4.2
Persisting Data with Volumes
Stop and remove the current influxdb container:
$ docker stop influxdb$ docker rm influxdb
Start a new instance of the influxdb database container:
$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ --memory 200m \ --memory-swap 1G \ --cpu-shares 1024 \ b.gcr.io/kuar/influxdb:0.9.4.2
Run the query to sum the pod count in the kubernetes test database again:
$ curl -G http://localhost:38086/query?pretty=true \ --data-urlencode "db=kubernetes" \ --data-urlencode "q=SELECT SUM(count) FROM pod"
Output:
{ "results": [ { "error": "database not found: kubernetes" } ]}
Let’s create a directory on our container host to house that volume.
$ mkdir /var/lib/influxdb/$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ --memory 200m \ --memory-swap 1G \ --cpu-shares 1024 \ --volume /var/lib/influxdb:/.influxdb \ b.gcr.io/kuar/influxdb:0.9.4.2
Create the kubernetes database:
$ curl -G 'http://localhost:38086/query' \ --data-urlencode "q=CREATE DATABASE kubernetes"
Add some data:
$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node0 count=10'$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node1 count=9'$ curl -X POST 'http://localhost:38086/write?db=kubernetes' \ -d 'pod,host=node2 count=12'
Run the pod sum query:
$ curl -G http://localhost:38086/query?pretty=true \ --data-urlencode "db=kubernetes" \ --data-urlencode "q=SELECT SUM(count) FROM pod"
Output:
{ "results": [ { "series": [ { "name": "pod", "columns": [ "time", "sum" ], "values": [ [ "1970-01-01T00:00:00Z", 31 ] ] } ] } ]}
First stop and remove the current influxdb container:
$ docker stop influxdb$ docker rm influxdb
Create the influxdb container again attaching the same host volume:
$ docker run -d --name influxdb \ --publish 38083:8083 \ --publish 38086:8086 \ --memory 200m \ --memory-swap 1G \ --cpu-shares 1024 \ --volume /var/lib/influxdb:/.influxdb \ b.gcr.io/kuar/influxdb:0.9.4.2
Run the pod sum query again:
$ curl -G http://localhost:38086/query?pretty=true \ --data-urlencode "db=kubernetes" \ --data-urlencode "q=SELECT SUM(count) FROM pod"
Output:
{ "results": [ { "series": [ { "name": "pod", "columns": [ "time", "sum" ], "values": [ [ "1970-01-01T00:00:00Z", 31 ] ] } ] } ]}
- KubernetesUpAndRunning-Containers
- KubernetesUpAndRunning-Introduction
- KubernetesUpAndRunning-Pods
- KubernetesUpAndRunning-Services
- Containers
- KubernetesUpAndRunning-Deploying Kubernetes
- KubernetesUpAndRunning-Labels and Annotations
- Sequentials Containers
- sequentail Containers
- Understanding Containers
- STL Containers
- Capability Containers
- Analysis containers
- Associative Containers
- Quickstart containers
- Networking Containers
- 容器Containers
- STL Containers
- relocation section 9 uses unexpected symbol table 0
- 乐观锁和悲观锁简介
- ADSL上网方式
- 数据结构之二叉树遍历的递归算法
- Java8内存模型—永久代(PermGen)和元空间(Metaspace)
- KubernetesUpAndRunning-Containers
- Flask提供的RESTful Web服务
- 关于linux下安装mysql碰到的~~
- wpf页面和导航
- 情人节,程序猿们在干嘛?
- Linux查看CPU和内存使用情况
- 九度OJ-1190:大整数排序
- 关于JavaScript数据类型NULL和Undefined
- 访问量分类统计(QQ,微信,微博,网页,网站APP,其他)