k8s 安装_K8s 安装

6336372e4c7a0189bc6cc1c7bce52555.png

​环境初始化

1:分别在2台主机设置主机名称

  1. hostnamectl set-hostname node1
  2. hostnamectl set-hostname node2

2:配置主机映射

  1. cat <<EOF > /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.124.129 node1
  5. 192.168.124.132 node2
  6. EOF

3:node1上执行ssh免密码登陆配置

  1. ssh-keygen #一路回车即可
  2. ssh-copy-id node2

4:两台主机配置、停防火墙、关闭Swap、关闭Selinux

  1. # 禁用防火墙:
  2. $ systemctl stop firewalld
  3. $ systemctl disable firewalld
  4. # 禁用SELINUX:
  5. $ setenforce 0
  6. $ cat /etc/selinux/config
  7. SELINUX=disabled
  8. # 创建/etc/sysctl.d/k8s.conf文件,添加如下内容
  9. cat <<EOF > /etc/sysctl.d/k8s.conf
  10. net.bridge.bridge-nf-call-ip6tables = 1
  11. net.bridge.bridge-nf-call-iptables = 1
  12. EOF
  13. sysctl --system
  14. #关闭系统Swap
  15. swapoff -a
  16. sed -i 's/.*swap.*/#&/' /etc/fstab

镜像准备

如果你的节点上面有科学上网的工具,可以忽略这一步,我们需要提前将所需的http://gcr.io上面的镜像下载到节点上面,当然前提条件是你已经成功安装了docker。

1、master节点,执行下面的命令:

  1. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.12.0
  2. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.12.0
  3. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.0
  4. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.12.0
  5. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.2.24
  6. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2
  7. docker pull cnych/flannel:v0.10.0-amd64
  8. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
  9. docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/kubernetes-dashboard-amd64:v1.8.3
  10. docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-grafana-amd64:v4.4.3
  11. docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-influxdb-amd64:v1.3.3
  12. docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-amd64:3.1
  1. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.12.0 k8s.gcr.io/kube-apiserver:v1.12.0
  2. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.12.0
  3. docker tag
  4. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.0 k8s.gcr.io/kube-proxy:v1.12.0
  5. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.12.0
  6. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
  7. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
  8. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
  9. docker tag cnych/flannel:v0.10.0-amd64:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64

2、slave节点,执行下面的命令:

  1. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.0
  2. docker pull cnych/flannel:v0.10.0-amd64
  3. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
  4. docker tag
  5. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.0 k8s.gcr.io/kube-proxy:v1.12.0
  6. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
  7. docker tag cnych/flannel:v0.10.0-amd64:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64

安装配置kubernetes

两个节点都需要安装
安装
  1. cat > /etc/yum.repos.d/kubernetes.repo <<EOF
  2. [kubernetes]
  3. name=Kubernetes
  4. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
  5. enabled=1
  6. gpgcheck=0
  7. repo_gpgcheck=0
  8. EOF

我们是安装最新版本的,所以直接yum install -y kubeadm即可,它会安装相应依赖包。

  1. 如果要指定版本,可以先看看有那些版本
  2. yum list kubeadm --showduplicates

配置 kubelet

修改文件kubelet的配置文件/etc/systemd/system/kubelet.service.d/10-kubeadm.conf, 配置文件中增加一项配置(在ExecStart之前):

  1. Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"

如图所示:

c0d714be9e29a1dd8ec806c24bd410f7.png
  1. # kubelet设置开机自动运行
  2. systemctl enable kubelet

启动kubelet:

  1. systemctl start kubelet

集群安装

  1. $ kubeadm init
  2. > --kubernetes-version=v1.12.0
  3. > --pod-network-cidr=10.244.0.0/16
  4. > --apiserver-advertise-address=192.168.124.129
  5. > --ignore-preflight-errors=Swap
  6. [init] using Kubernetes version: v1.12.0
  7. [preflight] running pre-flight checks
  8. [WARNING Swap]: running with swap on is not supported. Please disable swap
  9. [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 17.12.1-ce. Latest validated version: 18.06
  10. [preflight/images] Pulling images required for setting up a Kubernetes cluster
  11. [preflight/images] This might take a minute or two, depending on the speed of your internet connection
  12. [preflight/images] You can also perform this action in beforehand using 'kubeadm config images pull'
  13. [kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
  14. [kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
  15. [preflight] Activating the kubelet service
  16. [certificates] Generated etcd/ca certificate and key.
  17. [certificates] Generated etcd/server certificate and key.
  18. [certificates] etcd/server serving cert is signed for DNS names [node1 localhost] and IPs [127.0.0.1 ::1]
  19. [certificates] Generated etcd/peer certificate and key.
  20. [certificates] etcd/peer serving cert is signed for DNS names [node1 localhost] and IPs [192.168.124.129 127.0.0.1 ::1]
  21. [certificates] Generated apiserver-etcd-client certificate and key.
  22. [certificates] Generated etcd/healthcheck-client certificate and key.
  23. [certificates] Generated ca certificate and key.
  24. [certificates] Generated apiserver certificate and key.
  25. [certificates] apiserver serving cert is signed for DNS names [node1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.124.129]
  26. [certificates] Generated apiserver-kubelet-client certificate and key.
  27. [certificates] Generated front-proxy-ca certificate and key.
  28. [certificates] Generated front-proxy-client certificate and key.
  29. [certificates] valid certificates and keys now exist in "/etc/kubernetes/pki"
  30. [certificates] Generated sa key and public key.
  31. [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
  32. [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
  33. [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"
  34. [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
  35. [controlplane] wrote Static Pod manifest for component kube-apiserver to "/etc/kubernetes/manifests/kube-apiserver.yaml"
  36. [controlplane] wrote Static Pod manifest for component kube-controller-manager to "/etc/kubernetes/manifests/kube-controller-manager.yaml"
  37. [controlplane] wrote Static Pod manifest for component kube-scheduler to "/etc/kubernetes/manifests/kube-scheduler.yaml"
  38. [etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/manifests/etcd.yaml"
  39. [init] waiting for the kubelet to boot up the control plane as Static Pods from directory "/etc/kubernetes/manifests"
  40. [init] this might take a minute or longer if the control plane images have to be pulled
  41. [apiclient] All control plane components are healthy after 22.507741 seconds
  42. [uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
  43. [kubelet] Creating a ConfigMap "kubelet-config-1.12" in namespace kube-system with the configuration for the kubelets in the cluster
  44. [markmaster] Marking the node node1 as master by adding the label "node-role.kubernetes.io/master=''"
  45. [markmaster] Marking the node node1 as master by adding the taints [node-role.kubernetes.io/master:NoSchedule]
  46. [patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node1" as an annotation
  47. [bootstraptoken] using token: momf47.0scodcv3cm6t75vm
  48. [bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
  49. [bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
  50. [bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
  51. [bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
  52. [addons] Applied essential addon: CoreDNS
  53. [addons] Applied essential addon: kube-proxy
  54. Your Kubernetes master has initialized successfully!
  55. To start using your cluster, you need to run the following as a regular user:
  56. mkdir -p $HOME/.kube
  57. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  58. sudo chown $(id -u):$(id -g) $HOME/.kube/config
  59. You should now deploy a pod network to the cluster.
  60. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  61. https://kubernetes.io/docs/concepts/cluster-administration/addons/
  62. You can now join any number of machines by running the following on each node
  63. as root:
  64. kubeadm join 192.168.124.129:6443 --token momf47.0scodcv3cm6t75vm --discovery-token-ca-cert-hash sha256:cfeed429d671eeb39b8980ada10b55e79057cc65e108660ef86ae5043d6275f8

初始化主要过程为:

  • 1.kubeadm 执行初始化前的检查
  • 2.生成 token 和证书
  • 3.生成 KubeConfig 文件,kubelet 需要这个文件与 Master 通信。
  • 4.安装 Master 组件,会从 goolge 的 Registry 下载组件的 Docker 镜像,这一步可能会花一些时间,主要取决于网络质量,如果本地已有相关镜像则会优先使用本地的。
  • 5.安装附加组件 kube-proxy 和 kube-dns
  • 6.Kubernetes Master 初始化成功
  • 7.提示后续操作

初始化失败后处理办法

  1. kubeadm reset

node1上面执行如下命令

  1. mkdir -p $HOME/.kube
  2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3. sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubeadm生成证书密码文件分发到node2上面去

  1. scp -r /etc/kubernetes/pki node03:/etc/kubernetes/

部署flannel网络,只需要在node1执行就行

  1. $ wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  2. $ kubectl apply -f kube-flannel.yml
  1. $ kubectl get node
  2. NAME STATUS ROLES AGE VERSION
  3. node1 Ready master 5m32s v1.12.2

安装完成后使用kubectl get pods命令可以查看到我们集群中的组件运行状态,如果都是Running状态的话,那么恭喜你,你的master节点安装成功了。

  1. kubectl get pods --all-namespaces
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. kube-system coredns-576cbf47c7-mntdb 1/1 Running 0 5m20s
  4. kube-system coredns-576cbf47c7-rswvv 1/1 Running 0 5m20s
  5. kube-system etcd-node1 1/1 Running 0 4m33s
  6. kube-system kube-apiserver-node1 1/1 Running 0 4m44s
  7. kube-system kube-controller-manager-node1 1/1 Running 0 4m28s
  8. kube-system kube-flannel-ds-amd64-gxqq8 1/1 Running 0 24s
  9. kube-system kube-proxy-4xgvb 1/1 Running 0 5m20s
  10. kube-system kube-scheduler-node1 1/1 Running 0 4m38s

部署Dashboard插件

kubernetes-dashboard.yaml文件内容如下:

  1. # Copyright 2017 The Kubernetes Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Configuration to deploy release version of the Dashboard UI compatible with
  15. # Kubernetes 1.8.
  16. #
  17. # Example usage: kubectl create -f <this_file>
  18. # ------------------- Dashboard Secret ------------------- #
  19. apiVersion: v1
  20. kind: Secret
  21. metadata:
  22. labels:
  23. k8s-app: kubernetes-dashboard
  24. name: kubernetes-dashboard-certs
  25. namespace: kube-system
  26. type: Opaque
  27. ---
  28. # ------------------- Dashboard Service Account ------------------- #
  29. apiVersion: v1
  30. kind: ServiceAccount
  31. metadata:
  32. labels:
  33. k8s-app: kubernetes-dashboard
  34. name: kubernetes-dashboard
  35. namespace: kube-system
  36. ---
  37. # ------------------- Dashboard Role & Role Binding ------------------- #
  38. kind: Role
  39. apiVersion: rbac.authorization.k8s.io/v1
  40. metadata:
  41. name: kubernetes-dashboard-minimal
  42. namespace: kube-system
  43. rules:
  44. # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
  45. - apiGroups: [""]
  46. resources: ["secrets"]
  47. verbs: ["create"]
  48. # Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
  49. - apiGroups: [""]
  50. resources: ["configmaps"]
  51. verbs: ["create"]
  52. # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
  53. - apiGroups: [""]
  54. resources: ["secrets"]
  55. resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
  56. verbs: ["get", "update", "delete"]
  57. # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
  58. - apiGroups: [""]
  59. resources: ["configmaps"]
  60. resourceNames: ["kubernetes-dashboard-settings"]
  61. verbs: ["get", "update"]
  62. # Allow Dashboard to get metrics from heapster.
  63. - apiGroups: [""]
  64. resources: ["services"]
  65. resourceNames: ["heapster"]
  66. verbs: ["proxy"]
  67. - apiGroups: [""]
  68. resources: ["services/proxy"]
  69. resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
  70. verbs: ["get"]
  71. ---
  72. apiVersion: rbac.authorization.k8s.io/v1
  73. kind: RoleBinding
  74. metadata:
  75. name: kubernetes-dashboard-minimal
  76. namespace: kube-system
  77. roleRef:
  78. apiGroup: rbac.authorization.k8s.io
  79. kind: Role
  80. name: kubernetes-dashboard-minimal
  81. subjects:
  82. - kind: ServiceAccount
  83. name: kubernetes-dashboard
  84. namespace: kube-system
  85. ---
  86. # ------------------- Dashboard Deployment ------------------- #
  87. kind: Deployment
  88. apiVersion: apps/v1beta2
  89. metadata:
  90. labels:
  91. k8s-app: kubernetes-dashboard
  92. name: kubernetes-dashboard
  93. namespace: kube-system
  94. spec:
  95. replicas: 1
  96. revisionHistoryLimit: 10
  97. selector:
  98. matchLabels:
  99. k8s-app: kubernetes-dashboard
  100. template:
  101. metadata:
  102. labels:
  103. k8s-app: kubernetes-dashboard
  104. spec:
  105. nodeSelector:
  106. node-role.kubernetes.io/master: ""
  107. containers:
  108. - name: kubernetes-dashboard
  109. image: registry.cn-hangzhou.aliyuncs.com/k8sth/kubernetes-dashboard-amd64:v1.8.3
  110. ports:
  111. - containerPort: 8443
  112. protocol: TCP
  113. args:
  114. - --auto-generate-certificates
  115. # Uncomment the following line to manually specify Kubernetes API server Host
  116. # If not specified, Dashboard will attempt to auto discover the API server and connect
  117. # to it. Uncomment only if the default does not work.
  118. # - --apiserver-host=http://my-address:port
  119. volumeMounts:
  120. - name: kubernetes-dashboard-certs
  121. mountPath: /certs
  122. # Create on-disk volume to store exec logs
  123. - mountPath: /tmp
  124. name: tmp-volume
  125. livenessProbe:
  126. httpGet:
  127. scheme: HTTPS
  128. path: /
  129. port: 8443
  130. initialDelaySeconds: 30
  131. timeoutSeconds: 30
  132. volumes:
  133. - name: kubernetes-dashboard-certs
  134. secret:
  135. secretName: kubernetes-dashboard-certs
  136. - name: tmp-volume
  137. emptyDir: {}
  138. serviceAccountName: kubernetes-dashboard
  139. # Comment the following tolerations if Dashboard must not be deployed on master
  140. tolerations:
  141. - key: node-role.kubernetes.io/master
  142. effect: NoSchedule
  143. ---
  144. # ------------------- Dashboard Service ------------------- #
  145. kind: Service
  146. apiVersion: v1
  147. metadata:
  148. labels:
  149. k8s-app: kubernetes-dashboard
  150. name: kubernetes-dashboard
  151. namespace: kube-system
  152. spec:
  153. type: NodePort
  154. ports:
  155. - port: 443
  156. targetPort: 8443
  157. nodePort: 30000
  158. selector:
  159. k8s-app: kubernetes-dashboard
  160. ---
  161. apiVersion: v1
  162. kind: ServiceAccount
  163. metadata:
  164. name: admin-user
  165. namespace: kube-system
  166. ---
  167. apiVersion: rbac.authorization.k8s.io/v1beta1
  168. kind: ClusterRoleBinding
  169. metadata:
  170. name: admin-user
  171. roleRef:
  172. apiGroup: rbac.authorization.k8s.io
  173. kind: ClusterRole
  174. name: cluster-admin
  175. subjects:
  176. - kind: ServiceAccount
  177. name: admin-user
  178. namespace: kube-system

执行如下文件

  1. kubectl create -f kubernetes-dashboard.yaml

获取token,通过令牌登陆

  1. $ kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
  2. Name: admin-user-token-z6lhq
  3. Namespace: kube-system
  4. Labels: <none>
  5. Annotations: kubernetes.io/service-account.name: admin-user
  6. kubernetes.io/service-account.uid: 1b1a9541-ed6d-11e8-8458-000c2960d34d
  7. Type: kubernetes.io/service-account-token
  8. Data
  9. ====
  10. ca.crt: 1025 bytes
  11. namespace: 11 bytes
  12. token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXo2bGhxIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIxYjFhOTU0MS1lZDZkLTExZTgtODQ1OC0wMDBjMjk2MGQzNGQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.sdAwrS-tLEHY62ufIwZBrC58-yVsqMGV_AdeyFu8EBPpzdSfgCDemPIyEonGdz9cU6CLMpLnvJ4r7OLBexCaZ4WPIh_Q6N3YjK150d--3uzxQVxtoezVrrgBUCAUgC1KNewa0Suu32A-c-tPj2ykxSGpIYVDDQDQKqw_2E91diF-WKD9YMTl2H9sQU6N9RvSW7t0kQKcBFe8mDTUl4jrT-LnaISL_Qxcn0gwTlU-cbTBYuTpKvyLJ-aa6DfmFebQWA_Je-CLwh6ayk1X6DVVaSE_H5S9atGvnLQ1QVuj3ukHRtKnNSzAGM-boBaGTWZ0Khxo3sbsi7kvUZArYV1Vow

通过firefox访问dashboard,输入token,即可登陆

  1. https://192.168.124.129:30000/#!/login

安装heapster

  1. $ kubectl create -f kube-heapster/influxdb/
  2. $ kubectl create -f kube-heapster/rbac/

heapster文件信息:

  1. [root@node01 ~]# tree kube-heapster/
  2. kube-heapster/
  3. ├── influxdb
  4. ├── grafana.yaml
  5. ├── heapster.yaml
  6. └── influxdb.yaml
  7. └── rbac
  8. └── heapster-rbac.yaml

grafana.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: monitoring-grafana
  5. namespace: kube-system
  6. spec:
  7. replicas: 1
  8. template:
  9. metadata:
  10. labels:
  11. task: monitoring
  12. k8s-app: grafana
  13. spec:
  14. nodeSelector:
  15. node-role.kubernetes.io/master: ""
  16. containers:
  17. - name: grafana
  18. image: registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-grafana-amd64:v4.4.3
  19. imagePullPolicy: IfNotPresent
  20. ports:
  21. - containerPort: 3000
  22. protocol: TCP
  23. volumeMounts:
  24. - mountPath: /etc/ssl/certs
  25. name: ca-certificates
  26. readOnly: true
  27. - mountPath: /var
  28. name: grafana-storage
  29. env:
  30. - name: INFLUXDB_HOST
  31. value: monitoring-influxdb
  32. - name: GF_SERVER_HTTP_PORT
  33. value: "3000"
  34. # The following env variables are required to make Grafana accessible via
  35. # the kubernetes api-server proxy. On production clusters, we recommend
  36. # removing these env variables, setup auth for grafana, and expose the grafana
  37. # service using a LoadBalancer or a public IP.
  38. - name: GF_AUTH_BASIC_ENABLED
  39. value: "false"
  40. - name: GF_AUTH_ANONYMOUS_ENABLED
  41. value: "true"
  42. - name: GF_AUTH_ANONYMOUS_ORG_ROLE
  43. value: Admin
  44. - name: GF_SERVER_ROOT_URL
  45. # If you're only using the API Server proxy, set this value instead:
  46. # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
  47. value: /
  48. volumes:
  49. - name: ca-certificates
  50. hostPath:
  51. path: /etc/ssl/certs
  52. - name: grafana-storage
  53. emptyDir: {}
  54. ---
  55. apiVersion: v1
  56. kind: Service
  57. metadata:
  58. labels:
  59. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  60. # If you are NOT using this as an addon, you should comment out this line.
  61. kubernetes.io/cluster-service: 'true'
  62. kubernetes.io/name: monitoring-grafana
  63. name: monitoring-grafana
  64. namespace: kube-system
  65. spec:
  66. # In a production setup, we recommend accessing Grafana through an external Loadbalancer
  67. # or through a public IP.
  68. # type: LoadBalancer
  69. # You could also use NodePort to expose the service at a randomly-generated port
  70. # type: NodePort
  71. ports:
  72. - port: 80
  73. targetPort: 3000
  74. selector:
  75. k8s-app: grafana

heapster.yaml

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. name: heapster
  5. namespace: kube-system
  6. ---
  7. apiVersion: extensions/v1beta1
  8. kind: Deployment
  9. metadata:
  10. name: heapster
  11. namespace: kube-system
  12. spec:
  13. replicas: 1
  14. template:
  15. metadata:
  16. labels:
  17. task: monitoring
  18. k8s-app: heapster
  19. spec:
  20. serviceAccountName: heapster
  21. nodeSelector:
  22. node-role.kubernetes.io/master: ""
  23. containers:
  24. - name: heapster
  25. image: registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-amd64:v1.4.2
  26. imagePullPolicy: IfNotPresent
  27. command:
  28. - /heapster
  29. - --source=kubernetes:https://kubernetes.default
  30. - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086
  31. ---
  32. apiVersion: v1
  33. kind: Service
  34. metadata:
  35. labels:
  36. task: monitoring
  37. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  38. # If you are NOT using this as an addon, you should comment out this line.
  39. kubernetes.io/cluster-service: 'true'
  40. kubernetes.io/name: Heapster
  41. name: heapster
  42. namespace: kube-system
  43. spec:
  44. ports:
  45. - port: 80
  46. targetPort: 8082
  47. selector:
  48. k8s-app: heapster

influxdb.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: monitoring-influxdb
  5. namespace: kube-system
  6. spec:
  7. replicas: 1
  8. template:
  9. metadata:
  10. labels:
  11. task: monitoring
  12. k8s-app: influxdb
  13. spec:
  14. nodeSelector:
  15. node-role.kubernetes.io/master: ""
  16. containers:
  17. - name: influxdb
  18. image: registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-influxdb-amd64:v1.3.3
  19. imagePullPolicy: IfNotPresent
  20. volumeMounts:
  21. - mountPath: /data
  22. name: influxdb-storage
  23. volumes:
  24. - name: influxdb-storage
  25. emptyDir: {}
  26. ---
  27. apiVersion: v1
  28. kind: Service
  29. metadata:
  30. labels:
  31. task: monitoring
  32. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  33. # If you are NOT using this as an addon, you should comment out this line.
  34. kubernetes.io/cluster-service: 'true'
  35. kubernetes.io/name: monitoring-influxdb
  36. name: monitoring-influxdb
  37. namespace: kube-system
  38. spec:
  39. ports:
  40. - port: 8086
  41. targetPort: 8086
  42. selector:
  43. k8s-app: influxdb

heapster-rbac.yaml

  1. kind: ClusterRoleBinding
  2. apiVersion: rbac.authorization.k8s.io/v1beta1
  3. metadata:
  4. name: heapster
  5. roleRef:
  6. apiGroup: rbac.authorization.k8s.io
  7. kind: ClusterRole
  8. name: system:heapster
  9. subjects:
  10. - kind: ServiceAccount
  11. name: heapster
  12. namespace: kube-system

让master也运行pod(默认master不运行pod)

  1. kubectl taint nodes --all node-role.kubernetes.io/master-

添加node2节点到集群

在node2节点执行如下命令,即可将节点添加进集群

  1. kubeadm join 192.168.124.129:6443 --token momf47.0scodcv3cm6t75vm --discovery-token-ca-cert-hash sha256:cfeed429d671eeb39b8980ada10b55e79057cc65e108660ef86ae5043d6275f8 --ignore-preflight-errors=Swap
  2. [preflight] running pre-flight checks
  3. [WARNING RequiredIPVSKernelModulesAvailable]: the IPVS proxier will not be used, because the following required kernel modules are not loaded: [ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh] or no builtin kernel ipvs support: map[ip_vs:{} ip_vs_rr:{} ip_vs_wrr:{} ip_vs_sh:{} nf_conntrack_ipv4:{}]
  4. you can solve this problem with following methods:
  5. 1. Run 'modprobe -- ' to load missing kernel modules;
  6. 2. Provide the missing builtin kernel ipvs support
  7. [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 17.12.1-ce. Latest validated version: 18.06
  8. [discovery] Trying to connect to API Server "192.168.124.129:6443"
  9. [discovery] Created cluster-info discovery client, requesting info from "https://192.168.124.129:6443"
  10. [discovery] Requesting info from "https://192.168.124.129:6443" again to validate TLS against the pinned public key
  11. [discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.124.129:6443"
  12. [discovery] Successfully established connection with API Server "192.168.124.129:6443"
  13. [kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.12" ConfigMap in the kube-system namespace
  14. [kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
  15. [kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
  16. [preflight] Activating the kubelet service
  17. [tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
  18. [patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node2" as an annotation
  19. This node has joined the cluster:
  20. * Certificate signing request was sent to apiserver and a response was received.
  21. * The Kubelet was informed of the new secure connection details.
  22. Run 'kubectl get nodes' on the master to see this node join the cluster.
  1. $ kubectl get node
  2. NAME STATUS ROLES AGE VERSION
  3. node1 Ready master 78m v1.12.2
  4. node2 Ready <none> 64m v1.12.2
  1. $ kubectl get pods --all-namespaces
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. kube-system coredns-576cbf47c7-mntdb 1/1 Running 0 20m
  4. kube-system coredns-576cbf47c7-rswvv 1/1 Running 0 20m
  5. kube-system etcd-node1 1/1 Running 0 19m
  6. kube-system heapster-6955774cc5-gt4c8 1/1 Running 0 13m
  7. kube-system kube-apiserver-node1 1/1 Running 0 20m
  8. kube-system kube-controller-manager-node1 1/1 Running 0 19m
  9. kube-system kube-flannel-ds-amd64-2qzpw 1/1 Running 0 6m55s
  10. kube-system kube-flannel-ds-amd64-gxqq8 1/1 Running 0 15m
  11. kube-system kube-proxy-4xgvb 1/1 Running 0 20m
  12. kube-system kube-proxy-xhvfn 1/1 Running 0 6m55s
  13. kube-system kube-scheduler-node1 1/1 Running 0 20m
  14. kube-system kubernetes-dashboard-55f88765fb-qvm9w 1/1 Running 0 15m
  15. kube-system monitoring-grafana-9658ddc99-k8np4 1/1 Running 0 13m
  16. kube-system monitoring-influxdb-96bf68f65-9mn86 1/1 Running 0 13m

访问dashboard

cfbb480798e77189a1d9dbf99b48365f.png

56306c2e0692558f9a760fb883612ef4.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值