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 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是如何对各微服务暴露出来的业务接口进行管理??