本文共 5555 字,大约阅读时间需要 18 分钟。
前面的博文中介绍了k8s集群的部署,这里主要介绍部署kube-dns和Dashboard。
Node-1(Master): 10.0.0.1
Node-2: 10.0.0.2Node-3: 10.0.0.3集群使用二进制安装,并已部署flannel网络插件。
在进行如下的操作时,你必须已经部署好了K8S的集群,如果你还没有这样的集群,请参考我之前的博文。
1、在官网找到对应的yaml文件,地址为: , 我们修改相关配置,主要是ClusterIP的配置信息和镜像路径:
apiVersion: v1kind: ServiceAccountmetadata: name: coredns namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: Reconcile name: system:corednsrules:- apiGroups: - "" resources: - endpoints - services - pods - namespaces verbs: - list - watch---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: EnsureExists name: system:corednsroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:corednssubjects:- kind: ServiceAccount name: coredns namespace: kube-system---apiVersion: v1kind: ConfigMapmetadata: name: coredns namespace: kube-system labels: addonmanager.kubernetes.io/mode: EnsureExistsdata: Corefile: | .:53 { errors health kubernetes cluster.local. in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } prometheus :9153 proxy . /etc/resolv.conf cache 30 }---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS"spec: replicas: 2 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 selector: matchLabels: k8s-app: coredns template: metadata: labels: k8s-app: coredns spec: serviceAccountName: coredns tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule - key: "CriticalAddonsOnly" operator: "Exists" containers: - name: coredns image: coredns/coredns:1.0.6 imagePullPolicy: IfNotPresent resources: limits: memory: 170Mi requests: cpu: 100m memory: 70Mi args: [ "-conf", "/etc/coredns/Corefile" ] volumeMounts: - name: config-volume mountPath: /etc/coredns ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 dnsPolicy: Default volumes: - name: config-volume configMap: name: coredns items: - key: Corefile path: Corefile---apiVersion: v1kind: Servicemetadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS"spec: selector: k8s-app: coredns clusterIP: 10.222.0.100 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP
执行此yaml文件:
kubectl create -f coredns.yaml
查看文件状态:
[root@node-1 ~]# kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGEcoredns-77c989547b-2rg9h 1/1 Running 0 1hcoredns-77c989547b-cbj5h 1/1 Running 0 1h[root@node-1 ~]# kubectl get rs -n kube-systemNAME DESIRED CURRENT READY AGEcoredns-77c989547b 2 2 2 1h[root@node-1 ~]# kubectl get svc -n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEcoredns ClusterIP 10.222.0.10053/UDP,53/TCP 1h
下载官方的yaml文件,执行如下命令:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
只有安装了dns服务才能使用dashboard,否则将无法找到dashboard的service。
当dashboard服务启动后查看服务是否正常:
[root@node-1 ~]# kubectl get pod -n kube-systemNAME READY STATUS RESTARTS AGEcoredns-77c989547b-2rg9h 1/1 Running 0 2hcoredns-77c989547b-cbj5h 1/1 Running 0 2hkubernetes-dashboard-7d5dcdb6d9-h66fs 1/1 Running 0 1h[root@node-1 ~]# kubectl get svc -n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEcoredns ClusterIP 10.222.0.10053/UDP,53/TCP 2hkubernetes-dashboard ClusterIP 10.222.251.161 443/TCP 1h
使用代理,执行如下命令:
[root@node-1 ~]# kubectl proxy --port=8001 --address='10.0.0.1' --accept-hosts='^.*'Starting to serve on 10.0.0.1:8001
在浏览器中输入地址:
如果不出意外,会看到如下界面:
按照此提示创建用户
之后获取token,使用token登录:
kubectl describe secret -n kube-system `kubectl get secret -n kube-system |grep admin-user |awk '{print $1}'`
也可以通过master节点登录,访问此地址:
登录成功后显示主界面:
转载于:https://blog.51cto.com/tryingstuff/2129037