CoreOS实践(2)—在coreos上安装Kubernetes

下载kubernetes

sudo mkdir -p /opt/bin

sudo wget https://storage.googleapis.com/kubernetes/binaries.tar.gz

sudo tar -xvf binaries.tar.gz -C /opt/bin

 

git clone https://github.com/kelseyhightower/kubernetes-coreos.git

sudo cp kubernetes-coreos/units/* /etc/systemd/system/

 

启动docker服务

$ sudo vi /etc/systemd/system/docker.service

sudo systemctl daemon-reload      

sudo systemctl restart docker

sudo systemctl status docker

 

启动kubernetes的相关服务

sudo systemctl start apiserver

sudo systemctl start controller-manager

sudo systemctl start kubelet

sudo systemctl start proxy

 

sudo systemctl status apiserver

 apiserver.service - Kubernetes API Server

   Loaded: loaded (/etc/systemd/system/apiserver.service; disabled)

   Active: active (running) since Mon 2014-09-22 07:00:58 UTC; 5s ago

     Docs: https://github.com/GoogleCloudPlatform/kubernetes

 Main PID: 1099 (apiserver)

   CGroup: /system.slice/apiserver.service

           └─1099 /opt/bin/apiserver --address=127.0.0.1 --port=8080 --etcd_servers=http://127.0.0.1:4001 --mac...

 

Sep 22 07:00:58 core-01 systemd[1]: Starting Kubernetes API Server...

Sep 22 07:00:58 core-01 systemd[1]: Started Kubernetes API Server.

Sep 22 07:00:58 core-01 apiserver[1099]: I0922 07:00:58.466359 01099 apiserver.go:76] No cloud provider specified.

Sep 22 07:00:58 core-01 apiserver[1099]: E0922 07:00:58.470180 01099 healthy_registry.go:77] 127.0.0.1 fai...fused

Sep 22 07:00:58 core-01 apiserver[1099]: I0922 07:00:58.472353 01099 log.go:151] GET /api/v1beta1/services...) 200

Hint: Some lines were ellipsized, use -l to show in full.

NewImage

创建pod

$cat kubernetes-coreos/pods/redis.json

{

  "id": "redis",

  "desiredState": {

    "manifest": {

      "version": "v1beta1",

      "id": "redis",

      "containers": [{

        "name": "redis",

        "image": "dockerfile/redis",

        "ports": [{

          "containerPort": 6379,

          "hostPort": 6379

        }]

      }]

    }

  },

  "labels": {

    "name": "redis"

  }

}

 

$ /opt/bin/kubecfg -h http://127.0.0.1:8080 -c kubernetes-coreos/pods/redis.json create /pods

ID                  Image(s)            Host                Labels              Status

----------          ----------          ----------          ----------          ----------

redis               dockerfile/redis    /                   name=redis          Waiting

 

 

core@core-01 ~ $ kubecfg list /pods

ID                  Image(s)            Host                Labels              Status

----------          ----------          ----------          ----------          ----------

redis               dockerfile/redis    /                   name=redis          Waiting

 

在操作过程中发现pod的状态一直为Waiting状态。由于scheduler服务没有启动的原因,目前kelseyhightower/kubernetes-coreos还没有scheduler.service,但已经存在PR。参考这里

 

core@core-01 /etc/systemd/system $ cat scheduler.service

[Unit]

After=apiserver.service

ConditionFileIsExecutable=/opt/bin/scheduler

Description=Kubernetes Scheduler

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

Wants=apiserver.service

 

[Service]

ExecStart=/opt/bin/scheduler \

--logtostderr=true \

--master=127.0.0.1:8080

Restart=always

RestartSec=10

 

[Install]

WantedBy=multi-user.target

启动scheduler.service

NewImage

 

测试redis

docker run -t -i dockerfile/redis /usr/local/bin/redis-cli -h 10.1.42.1

10.1.42.1:6379> help

redis-cli 2.8.17

Type: "help @<group>" to get a list of commands in <group>

      "help <command>" for help on <command>

      "help <tab>" to get a list of possible help topics

      "quit" to exit

10.1.42.1:6379> help set

 

  SET key value [EX seconds] [PX milliseconds] [NX|XX]

  summary: Set the string value of a key

  since: 1.0.0

  group: string

 

10.1.42.1:6379> SET key1 value1

OK

10.1.42.1:6379> help get

 

  GET key

  summary: Get the value of a key

  since: 1.0.0

  group: string

 

10.1.42.1:6379> GET key1

"value1"

 

主要参考

[1] https://github.com/kelseyhightower/kubernetes-coreos

[2] https://coreos.com/blog/running-kubernetes-example-on-CoreOS-part-1/

 


作者:YY哥 
出处:http://www.cnblogs.com/hustcat/ 
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 

posted @ 2014-09-22 20:06  YY哥  阅读(7798)  评论(0编辑  收藏  举报