kubernetes 安裝備註

1、安裝環境node

  阿里雲:centos 7.3web

  master節點:外網IP(116.62.205.90)、內網IP(172.16.223.200)spring

  node節點:外網IP(116.62.212.174)、內網IP(172.16.223.201)docker

 

2、Master節點安裝步驟centos

一、在master節點上安裝etcdapi

備註:etcd是用於共享配置和服務發現的分佈式,一致性的KV存儲系統,相似ZK和consul瀏覽器

  執行命令:yum -y install etcdtomcat

  修改/etc/etcd/etcd.conf文件,主要修改以下:服務器

ETCD_LISTEN_PEER_URLS="http://172.16.223.200:2380"
ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.223.200:2379"

ETCD_ADVERTISE_CLIENT_URLS="http://172.16.223.200:2379"

二、在master節點上安裝kubernetes-master網絡

  執行命令:yum -y install kubernetes-master

  修改配置文件/etc/kubernetes/apiserver:

###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#

# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

# The port on the local server to listen on.
# KUBE_API_PORT="--port=8080"

# Port minions listen on
# KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://172.16.223.200:2379"

# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=172.17.0.0/16"

# default admission control policies
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"

# Add your own!
KUBE_API_ARGS=""

  修改配置文件/etc/kubernetes/config,主要修改以下:

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://116.62.205.90:8080"

  修改配置文件/etc/kubernetes/controller-manager,主要修改以下:

KUBE_CONTROLLER_MANAGER_ARGS="--node-monitor-grace-period=10s --pod-eviction-timeout=10s"

三、在master節點的etcd中增長網絡配置項

  執行命令:etcdctl mk /coreos.com/network/config '{"Network":"172.17.0.0/16"}' 

  此網段地址將被flanneld調用,若與本機局域網IP同網段彷佛不行;

四、啓動kubernetes-master節點的相關進程

  執行命令:systemctl start etcd kube-apiserver kube-scheduler kube-controller-manager

 

3、NODE節點安裝步驟

一、在node節點安裝kubernetes-node

  執行命令:yum -y install kubernetes-node

  修改/etc/kubernetes/config,主要修改參數以下:

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://116.62.205.90:8080"

  修改配置文件/etc/kubernetes/kubelet,主要修改參數以下:

###
# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=127.0.0.1"

# The port for the info server to serve on
# KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=172.16.223.201"

# location of the api-server
KUBELET_API_SERVER="--api-servers=http://116.62.205.90:8080"

# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

# Add your own!
KUBELET_ARGS=""

二、在node節點安裝flannel

  備註:Flannel是CoreOS團隊針對Kubernetes設計的一個網絡規劃服務,簡單來講,它的功能是讓集羣中的不一樣節點主機建立的Docker容器都具備全集羣惟一的虛擬IP地址。

  執行命令:yum -y install  flannel

  修改配置文件/etc/kubernetes/flanneld

# Flanneld configuration options  

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://172.16.223.200:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/coreos.com/network"

# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

備註:此處coreos.com這個域名須要和master服務器中etcd存儲的域名一致

三、啓動node節點的各項服務:

  執行命令:

  systemctl start flanneld

  systemctl start docker

  systemctl start kubelet

  systemctl start kube-proxy

 

4、安裝驗證及基本使用

一、驗證安裝是否成功:

  執行命令:kubernetes get node  可獲取當前的可用node服務器,狀態爲ready

  在瀏覽器上訪問8080域名,因能反饋master apiserver所提供的API列表

二、使用kubernutes進行容器編排:

  1)、首先在node服務器上下載images

  2)、在master服務器上編輯yaml文件,內容以下:

apiVersion: v1  
kind: Service  
metadata:  
  name: fred-srv-2 
spec:  
  type: NodePort  
  ports:  
    - port: 8080  
      nodePort: 31006 
  selector:  
    app: fred-web-2 

apiVersion: v1  
kind: ReplicationController  
metadata:  
  name: fred-web-2 
spec:  
  replicas: 1  
  template:  
    metadata:  
      labels:  
        app: fred-web-2 
    spec:  
      containers:  
        - name: test-tomcat  
          image: daocloud.io/library/tomcat 
          imagePullPolicy: IfNotPresent  
          ports:  
            - containerPort: 8080

  3)、執行命令:kubectl create -f tomcat.yaml

  4)、完成後檢查結果以下:

    1)執行kubectl get rc 因能看見建立的rc fred-web-2

    2)執行kubectl get svc 因能看見建立的svc fred-svc-2

    3)執行kubectl get po 因能看見建立的po fred-web-2-XXXX,此時因爲replicas參數爲1,所以建立了一個po

    4)訪問node服務器外網IP:31006,能夠訪問該po所在的tomcat ROOT頁面;

 

5、其餘:

  一、可使用kubectl delete -f tomcat.yaml 刪除建立的資源;

  二、調用journalctl可查看kubenertes本身的錯誤日誌;

  三、初步認識kubernetes的感受是一個編排docker容器的集羣,也就是master節點經過資源文件的設置在node節點上批量建立docker容器;

這些天在一本書上把kubernetes當作是一個微服務的框架,與spring cloud等對標,對此感受還不能理解;沒有看到kubernetes是如何對各微服務暴露出來的業務接口進行管理??

相關文章
相關標籤/搜索