[关闭]
@zhaikun 2017-07-20T15:50:15.000000Z 字数 9369 阅读 1248

kubernetes环境部署

docker


一、安装master

1、关闭防火墙&selinux

2、安装docker

3、修改hosts

  1. [root@zk-k8s-master01 ~]# vim /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 172.16.138.120 zk-k8s-master01
  5. 172.16.138.121 zk-k8s-node01

4、安装master

  1. [root@zk-k8s-master01 ~]# yum install -y kubernetes etcd flannel
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.aliyun.com
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package etcd.x86_64 0:3.1.9-1.el7 will be installed
  8. ---> Package flannel.x86_64 0:0.7.1-1.el7 will be installed
  9. ---> Package kubernetes.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
  10. --> Processing Dependency: kubernetes-node = 1.5.2-0.7.git269f928.el7 for package: kubernetes-1.5.2-0.7.git269f928.el7.x86_64
  11. --> Processing Dependency: kubernetes-master = 1.5.2-0.7.git269f928.el7 for package: kubernetes-1.5.2-0.7.git269f928.el7.x86_64
  12. --> Running transaction check
  13. ---> Package kubernetes-master.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
  14. ......

5、修改配置文件

  1. ###
  2. # kubernetes system config
  3. #
  4. # The following values are used to configure various aspects of all
  5. # kubernetes services, including
  6. #
  7. # kube-apiserver.service
  8. # kube-controller-manager.service
  9. # kube-scheduler.service
  10. # kubelet.service
  11. # kube-proxy.service
  12. # logging to stderr means we get it in the systemd journal
  13. KUBE_LOGTOSTDERR="--logtostderr=true"
  14. # journal message level, 0 is debug
  15. KUBE_LOG_LEVEL="--v=0"
  16. # Should this cluster be allowed to run privileged docker containers
  17. KUBE_ALLOW_PRIV="--allow-privileged=false"
  18. # How the controller-manager, scheduler, and proxy find the apiserver
  19. KUBE_MASTER="--master=http://zk-k8s-master01:8080" #修改为master地址

6、配置etcd

  1. # [member]
  2. ETCD_NAME=default
  3. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  4. #ETCD_WAL_DIR=""
  5. #ETCD_SNAPSHOT_COUNT="10000"
  6. #ETCD_HEARTBEAT_INTERVAL="100"
  7. #ETCD_ELECTION_TIMEOUT="1000"
  8. #ETCD_LISTEN_PEER_URLS="http://localhost:2380"
  9. ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" #修改为本机地址或者0.0.0.0
  10. #ETCD_MAX_SNAPSHOTS="5"
  11. #ETCD_MAX_WALS="5"
  12. #ETCD_CORS=""
  13. #
  14. #[cluster]
  15. #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380"
  16. # if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
  17. #ETCD_INITIAL_CLUSTER="default=http://localhost:2380"
  18. #ETCD_INITIAL_CLUSTER_STATE="new"
  19. #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  20. ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" #修改为本机地址或者0.0.0.0
  21. #ETCD_DISCOVERY=""
  22. #ETCD_DISCOVERY_SRV=""
  23. #ETCD_DISCOVERY_FALLBACK="proxy"
  24. #ETCD_DISCOVERY_PROXY=""
  25. [root@zk-k8s-master01 ~]# vim /etc/kubernetes/apiserver
  26. ###
  27. # kubernetes system config
  28. #
  29. # The following values are used to configure the kube-apiserver
  30. #
  31. # The address on the local server to listen to.
  32. KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
  33. # The port on the local server to listen on.
  34. KUBE_API_PORT="--port=8080"
  35. # Port minions listen on
  36. KUBELET_PORT="--kubelet-port=10250"
  37. # Comma separated list of nodes in the etcd cluster
  38. KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
  39. # Address range to use for services
  40. KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
  41. # default admission control policies
  42. KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
  43. # Add your own!
  44. KUBE_API_ARGS=""
  45. ......

7、注册FLANNEL

  1. [root@zk-k8s-master01 ~]# service etcd start
  2. [root@zk-k8s-master01 ~]# etcdctl mkdir /kube-centos/network
  3. [root@zk-k8s-master01 ~]# etcdctl mk /kube-centos/network/config "{ \"Network\": \"172.30.0.0/16\", \"SubnetLen\": 24, \"Backend\": { \"Type\": \"vxlan\" } }"
  4. { "Network": "172.30.0.0/16", "SubnetLen": 24, "Backend": { "Type": "vxlan" } }
  5. [root@zk-k8s-master01 ~]#
  6. #配置flannel
  7. [root@zk-k8s-master01 ~]# vim /etc/sysconfig/flanneld
  8. # Flanneld configuration options
  9. # etcd url location. Point this to the server where etcd runs
  10. FLANNEL_ETCD_ENDPOINTS="http://127.0.0.1:2379"
  11. # etcd config key. This is the configuration key that flannel queries
  12. # For address range assignment
  13. FLANNEL_ETCD_PREFIX="/kube-centos/network"
  14. # Any additional options that you want to pass
  15. #FLANNEL_OPTIONS=""

8、启动服务

  1. [root@zk-k8s-master01 ~]# for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do
  2. >
  3. > systemctl restart $SERVICES
  4. >
  5. > systemctl enable $SERVICES
  6. >
  7. > systemctl status $SERVICES
  8. >
  9. > done

二、安装node

1、关闭防火墙&selinux

2、安装docker

3、修改hosts

4、安装node

  1. [root@zk-k8s-node01 ~]# yum -y install kubernetes-node flannel
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.aliyun.com
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package flannel.x86_64 0:0.7.1-1.el7 will be installed
  8. ---> Package kubernetes-node.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
  9. --> Processing Dependency: kubernetes-client = 1.5.2-0.7.git269f928.el7 for package: kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64
  10. --> Processing Dependency: socat for package: kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64
  11. --> Processing Dependency: conntrack-tools for package: kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64
  12. --> Running transaction check
  13. ---> Package conntrack-tools.x86_64 0:1.4.4-3.el7_3 will be installed
  14. --> Processing Dependency: libnetfilter_conntrack >= 1.0.6 for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  15. --> Processing Dependency: libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.1)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  16. --> Processing Dependency: libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.0)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  17. --> Processing Dependency: libnetfilter_cthelper.so.0(LIBNETFILTER_CTHELPER_1.0)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  18. --> Processing Dependency: libnetfilter_queue.so.1()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  19. --> Processing Dependency: libnetfilter_cttimeout.so.1()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  20. --> Processing Dependency: libnetfilter_cthelper.so.0()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
  21. ---> Package kubernetes-client.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
  22. ---> Package socat.x86_64 0:1.7.2.2-5.el7 will be installed
  23. --> Running transaction check
  24. ......

5、修复配置

  1. [root@zk-k8s-node01 ~]# vim /etc/kubernetes/config
  2. ###
  3. # kubernetes system config
  4. #
  5. # The following values are used to configure various aspects of all
  6. # kubernetes services, including
  7. #
  8. # kube-apiserver.service
  9. # kube-controller-manager.service
  10. # kube-scheduler.service
  11. # kubelet.service
  12. # kube-proxy.service
  13. # logging to stderr means we get it in the systemd journal
  14. KUBE_LOGTOSTDERR="--logtostderr=true"
  15. # journal message level, 0 is debug
  16. KUBE_LOG_LEVEL="--v=0"
  17. # Should this cluster be allowed to run privileged docker containers
  18. KUBE_ALLOW_PRIV="--allow-privileged=false"
  19. # How the controller-manager, scheduler, and proxy find the apiserver
  20. KUBE_MASTER="--master=http://zk-k8s-master01:8080"
  21. [root@zk-k8s-node01 ~]# vim /etc/kubernetes/kubelet
  22. ###
  23. # kubernetes kubelet (minion) config
  24. # The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
  25. KUBELET_ADDRESS="--address=0.0.0.0"
  26. # The port for the info server to serve on
  27. # KUBELET_PORT="--port=10250"
  28. # You may leave this blank to use the actual hostname
  29. KUBELET_HOSTNAME="--hostname-override=zk-k8s-node01"
  30. # location of the api-server
  31. KUBELET_API_SERVER="--api-servers=http://zk-k8s-master01:8080"
  32. # pod infrastructure container
  33. KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=harbor.suixingpay.com/kube/pause-amd64:3.0"
  34. # Add your own!
  35. KUBELET_ARGS="--cluster_dns=10.254.0.100 --cluster_domain=cluster.local"

6、配置flannel

  1. [root@zk-k8s-node01 ~]# vim /etc/sysconfig/flanneld
  2. # Flanneld configuration options
  3. # etcd url location. Point this to the server where etcd runs
  4. FLANNEL_ETCD_ENDPOINTS="http://zk-k8s-master01:2379"
  5. # etcd config key. This is the configuration key that flannel queries
  6. # For address range assignment
  7. FLANNEL_ETCD_PREFIX="/kube-centos/network"
  8. # Any additional options that you want to pass
  9. #FLANNEL_OPTIONS=""

7、启动服务

  1. [root@zk-k8s-node01 ~]# for SERVICES in kube-proxy kubelet flanneld docker; do
  2. >
  3. > systemctl restart $SERVICES
  4. >
  5. > systemctl enable $SERVICES
  6. >
  7. > systemctl status $SERVICES
  8. >
  9. > done

三、安装kubernetes-dashbord(WEBUI)

kubernetes-dashboard.yamldashbord

  1. [root@zk-k8s-master01 docker]# vim kubernetes-dashboard.yaml
  2. .....
  3. spec:
  4. containers:
  5. - name: kubernetes-dashboard
  6. image: harbor.suixingpay.com/kube/k8s-dashboard:1.6.0 #修改为本地仓库的地址
  7. imagePullPolicy: IfNotPresent #修改为IfNotPresent模式 IfNotPresent是如果存在不下载安装
  8. ports:
  9. - containerPort: 9090
  10. protocol: TCP
  11. args:
  12. # Uncomment the following line to manually specify Kubernetes API server Host
  13. # If not specified, Dashboard will attempt to auto discover the API server and connect
  14. # to it. Uncomment only if the default does not work.
  15. - --apiserver-host=http://172.16.138.120:8080 #修改为master地址
  16. livenessProbe:
  17. httpGet:
  18. path: /
  19. port: 9090
  20. initialDelaySeconds: 30
  21. timeoutSeconds: 30
  22. ......
  23. [root@zk-k8s-master01 docker]# kubectl create -f kubernetes-dashboard.yaml
  24. deployment "kubernetes-dashboard" created
  25. service "kubernetes-dashboard" created
  26. [root@zk-k8s-master01 docker]#
  27. 注:
  28. node节点启动docker 配置 /etc/sysconfig/docker
  29. ADD_REGISTRY='--add-registry harbor.suixingpay.com'
  30. INSECURE_REGISTRY='--insecure-registry harbor.suixingpay.com

kubernetes-dashbord

四、安装skydns(DNS)

配置
skydns-rc.yamlrc
skydns-svc.yamlsvc

  1. [root@zk-k8s-master01 docker]# kubectl create -f skydns-rc.yaml
  2. deployment "kube-dns" created
  3. [root@zk-k8s-master01 docker]# kubectl create -f skydns-svc.yaml
  4. service "kube-dns" created
  5. [root@zk-k8s-master01 docker]#

五、安装heapster(监控)

配置
heapster-1.2.0.tar.gz未知大小

  1. 1)下载组件包:
  2. harbor.suixingpay.com/kube/heapster:canary
  3. harbor.suixingpay.com/kube/heapster_influxdb:v0.5
  4. harbor.suixingpay.com/kube/heapster_grafana:v2.6.0-2
  5. 2)修改heapster的配置文件,文件位置解压heapster-1.2.0.tar.gz文件
  6. heapster-1.2.0/deploy/kube-config/influxdb/
  7. 3)修改heapster-controller.yaml文件中对应images,然后修改最后两句为:
  8. - --source=kubernetes:http://172.16.138.101:8080?inClusterConfig=false
  9. - --sink=influxdb:http://monitoring-influxdb:8086
  10. 4)修改influxdb-grafana-controller.yaml文件中的对应images地址。
  11. 5) 安装资源 kubectl create -f . (在heapster-1.2.0/deploy/kube-config/influxdb/目录中执行)

监控页面

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注