k8s 基礎(4) k8s安裝

轉自 http://www.cnblogs.com/informatics/p/7389806.htmlhtml

安裝和配置node

從github.com/kubernetes/kubernetes上下載1.6.8已編譯好的二進制文件linux

tar xzvf kubernetes.tar.gz
cd kubernetes
./cluster/get-kube-binaries.sh

執行該shell會自動下載kube的server和client可執行文件,其中客戶端文件會自動安裝在kubernetes目錄下的client文件夾下,只需將bin添加到PATH下就能夠了。git

能夠不用管這裏的bin,server的可執行包裏也包含了客戶端命令行工具github

服務端可執行文件下載到了server文件夾,沒有被自動展開docker

cd server tar xzvf kubernetes-server-linux-amd64.tar.gz

 

執行該shell會自動下載kube的server和client可執行文件,其中客戶端文件會自動安裝在kubernetes目錄下的client文件夾下,服務端文件會安裝在kubernetes/server/kubernetes/server/bin/下面(包含客戶端文件)shell

master節點須要:kube-apiserver, kube-controller-manager, kube-schedulerapi

node節點須要:kubelet和kube-proxycors

這些程序咱們經過systemctl的方式來進行管理(包括etcd)ide

一、master配置

kube-etcd.service

複製代碼

[Unit]
Description=Kube-etcd Service
After=network.target

[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \
--name "etcd1" \
--data-dir="~/.k8s/etcd" \
--listen-client-urls "http://192.168.0.222:2379,http://127.0.0.1:2379" \
--listen-peer-urls "http://192.168.0.222:2380" \
--advertise-client-urls "http://192.168.0.222:2379" \
--initial-advertise-peer-urls "http://192.168.0.222:2380" \
--initial-cluster "etcd1=http://192.168.0.222:2380" \
--initial-cluster-state "new"
Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target

複製代碼

kube-apiserver.service

複製代碼
[Unit]
Description=Kube-apiserver Service
After=network.target

[Service]
Type=notify
ExecStart=/usr/local/bin/kube-apiserver \
            --admission-control=NamespaceAutoProvision,LimitRanger,SecurityContextDeny \
            --apiserver-count=1 \
            --cors-allowed-origins=.* \
            --enable-garbage-collector=false \
            --etcd-servers=http://192.168.0.222:2379 \
            --insecure-bind-address=0.0.0.0 \
            --insecure-port=8080 \
            --log-dir=~/.kube/log/kube-apiserver \
            --logtostderr=false \
            --service-cluster-ip-range=192.168.0.222/24 \
            --v=5 \

Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target
複製代碼

kube-controller-manager.service

複製代碼
[Unit]
Description=Kube-controller-manager Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/kube-controller-manager \
          --enable-garbage-collector=false \
          --logtostderr=false \
          --log-dir=~/.kube/log/kube-controller-manager \
          --pod-eviction-timeout=5m0s \
          --master=http://0.0.0.0:8080 \
          --node-monitor-grace-period=40s \
          --terminated-pod-gc-threshold=12500 \
          --leader-elect=true \
          --v=4 \

Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target
複製代碼

 

kube-scheduler.service

複製代碼
[Unit]
Description=Kube-scheduler Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/kube-scheduler \
            --log-dir=~/.k8s/log/kube-scheduler \
            --logtostderr=false \
            --master=http://0.0.0.0:8080 \
            --leader-elect=true \
            --v=5 \

Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target
複製代碼

注意修改本身的IP地址,下面啓動服務……

複製代碼
//add to path

cd etcd-v3.2.5-linux-amd64; sudo cp -rf etcd /usr/local/bin
cd kubernetes/server/kubernetes/server/bin/; sudo cp -rf kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin
sudo cp -rf kube-etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service /lib/systemd/system/

//start server
sudo -i
systemctl --system daemon-reload systemctl start kube-apiserver.service systemctl start kube-controller-manager.service systemctl start kube-scheduler.service
複製代碼

 2. node  1

kubelet.service

複製代碼
[Unit]
Description=Kubelet Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/kubelet \
            --api-servers=http://192.168.0.222:8080 \
            --hostname-override=10.0.48.50 \
            --image-gc-high-threshold=80 \
            --image-gc-low-threshold=50 \
            --log-dir=~/.k8s/log/kubelet \
            --logtostderr=false \
            --pod-infra-container-image=docker.cloudin.com/google_containers/pause-amd64:3.0 \
            --system-reserved cpu=2000m,memory=4G \
            --v=5 \

Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target
複製代碼

kube-proxy.service

複製代碼
[Unit]
Description=Kube-proxy Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/kube-proxy  \
            --log-dir=~/.k8s/log/kube-proxy \
            --logtostderr=false \
            --master=http://10.0.48.50:8080 \
            --v=5 \

Restart=always
LimitNOFILE=65536

[Install]
WantedBy=default.target
複製代碼
node 2須要將相應ip地址中的10.0.48.50改成10.0.48.59
下面啓動服務……
複製代碼
//add to path
cd kubernetes/server/kubernetes/server/bin/; sudo cp -rf kubelet kube-proxy /usr/local/bin sudo cp -rf kubelet.service kube-proxy.service /lib/systemd/system/

//start
sudo -i
systemctl --system daemon-reload systemctl start kubelet.service systemctl start kube-proxy.service
複製代碼

 三、測試環境是否搭建成功

複製代碼
$kubectl get nodes
NAME         STATUS     AGE       VERSION
10.0.48.50   NotReady   1h        v1.6.8
10.0.48.59   Ready      1h        v1.6.8
$kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.0.0.1 <none> 443/TCP 1h
相關文章
相關標籤/搜索