CentOS7.3下yum安装Kubernetes1.4入门教程(2)

配置master服务器

1) 配置kube-apiserver配置文件 [root@master ~]# grep -v '^#' /etc/kubernetes/config KUBE_LOGTOSTDERR="--logtostderr=true" KUBE_LOG_LEVEL="--v=0" KUBE_ALLOW_PRIV="--allow-privileged=false" KUBE_MASTER="--master=http://192.168.3.51:8080" [root@master ~]# [root@master ~]# grep -v '^#' /etc/kubernetes/apiserver [root@master ~]# grep -v '^#' /etc/kubernetes/apiserver KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.3.52:2379" KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" KUBE_ADMISSION_CONTROL="--admission-control=AlwaysAdmit" KUBE_API_ARGS="" [root@master ~]# 2) 配置kube-controller-manager配置文件 [root@master ~]# grep -v '^#' /etc/kubernetes/controller-manager KUBE_CONTROLLER_MANAGER_ARGS="" [root@master ~]# 3) 配置kube-scheduler配置文件 [root@master ~]# grep -v '^#' /etc/kubernetes/scheduler KUBE_SCHEDULER_ARGS="--address=0.0.0.0" [root@master ~]# 4) 启动服务 for SERVICES in kube-apiserver kube-controller-manager kube-scheduler do systemctl restart SERVICES done

配置node1节点服务器

1) 配置etcd [root@etcd ~]# etcdctl set /k8s/network/config '{"Network": "10.255.0.0/16"}' {"Network": "10.255.0.0/16"} [root@etcd ~]# etcdctl get /k8s/network/config {"Network": "10.255.0.0/16"} [root@etcd ~]# 2) 配置node1网络,本实例采用flannel方式来配置,如需其他方式,请参考Kubernetes官网。 [root@node1 ~]# grep -v '^#' /etc/sysconfig/flanneld FLANNEL_ETCD_ENDPOINTS="http://192.168.3.52:2379" FLANNEL_ETCD_PREFIX="/k8s/network" FLANNEL_OPTIONS="--iface=ens33" [root@node1 ~]# 备注:ens33用ip a命令获取,根据实际情况更改 3) 配置node1 kube-proxy [root@node1 ~]# grep -v '^#' /etc/kubernetes/config KUBE_LOGTOSTDERR="--logtostderr=true" KUBE_LOG_LEVEL="--v=0" KUBE_ALLOW_PRIV="--allow-privileged=false" KUBE_MASTER="--master=http://192.168.3.51:8080" [root@node1 ~]# [root@node1 ~]# grep -v '^#' /etc/kubernetes/proxy KUBE_PROXY_ARGS="--bind=address=0.0.0.0" [root@node1 ~]# 4) 配置node1 kubelet [root@node1 ~]# grep -v '^#' /etc/kubernetes/kubelet KUBELET_ADDRESS="--address=127.0.0.1" KUBELET_HOSTNAME="--hostname-override=node1" KUBELET_API_SERVER="--api-servers=http://192.168.3.51:8080" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.RedHat.com/rhel7/pod-infrastructure:latest" KUBELET_ARGS="" [root@node1 ~]# 5) 启动node1服务 for SERVICES in flanneld kube-proxy kubelet; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done

配置node2节点服务器

1) 配置node2网络,本实例采用flannel方式来配置,如需其他方式,请参考Kubernetes官网。 [root@node2 ~]# grep -v '^#' /etc/sysconfig/flanneld FLANNEL_ETCD_ENDPOINTS="http://192.168.3.52:2379" FLANNEL_ETCD_PREFIX="/k8s/network" FLANNEL_OPTIONS="--iface=eno16777736" [root@node2 ~]# 备注:eno16777736用ip a命令获取,根据实际情况更改 2) 配置node2 kube-proxy [root@node2 ~]# grep -v '^#' /etc/kubernetes/config KUBE_LOGTOSTDERR="--logtostderr=true" KUBE_LOG_LEVEL="--v=0" KUBE_ALLOW_PRIV="--allow-privileged=false" KUBE_MASTER="--master=http://192.168.3.51:8080" [root@node2 ~]# [root@node2 ~]# grep -v '^#' /etc/kubernetes/proxy KUBE_PROXY_ARGS="--bind-address=0.0.0.0" [root@node2 ~]# 3) 配置node2 kubelet [root@node2 ~]# grep -v '^#' /etc/kubernetes/kubelet KUBELET_ADDRESS="--address=127.0.0.1" KUBELET_HOSTNAME="--hostname-override=node1" KUBELET_API_SERVER="--api-servers=http://192.168.3.51:8080" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest" KUBELET_ARGS="" [root@node2 ~]# 4) 启动node2服务 for SERVICES in flanneld kube-proxy kubelet docker; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done

至此,整个Kubernetes集群搭建完毕

[root@master ~]# kubectl get nodes NAME STATUS AGE node1 Ready 34m node2 Ready 2m [root@master ~]#

三、在上面的集群上搭建基于Redis和docker的留言簿案例

1、启动Redis master
  使用deployment确保只有一个pod在运行(当某个节点down了,deploy会在另一个健康的node启动redis master),但可能会有数据丢失。

[root@master guestbook]# kubectl create -f redis-master-deployment.yaml deployment "redis-master" created [root@master guestbook]# [root@master guestbook]# kubectl get deploy NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE redis-master 1 1 1 1 3m [root@master guestbook]# [root@master guestbook]# kubectl get pods NAME READY STATUS RESTARTS AGE redis-master-517881005-c3qek 1/1 Running 0 4m [root@master guestbook]#

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d1d899bb415c375f0627e2705c28ab06.html