二进制安装K8s之部署CoreDNS 和Dashboard
CoreDNS 和Dashboard 的yaml文件在 k8s源代码压缩包里面可以找到对应的配置文件,很多人从网上直接下载使用别人的,会导致问多问题,k8s aipverson 每个版本略有不同。
下载与自己集群版本一样的源码文件,这里使用1.20
wget https://storage.googleapis.com/kubernetes-release/release/v1.20.9/kubernetes.tar.gz
#解压
tar -zxvf kubernetes.tar.gz
1、coredns.yaml 文件需要修改的内容如下:
CoreDNS 文件路径(源码文件路径)
./kubernetes/cluster/addons/dns/coredns/
image: registry.com/public/k8s.gcr.io/coredns:1.7.0
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 170Mi #修改
requests:
cpu: 100m
memory: 70Mi
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
selector:
k8s-app: kube-dns
clusterIP: 10.0.0.2 #修改dnsip
ports:
- name: dns
port: 53
protocol: UDP
#执行
kubectl apply -f coredns.yaml
2、创建service account并绑定默认cluster-admin管理员集群角色:
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
3、查看状态
所有的STATUS :Running 都必须显示 READY显示 1/1
[root@k8s-master01 ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-567b6cf877-lf8t6 1/1 Running 0 8m24s
calico-node-j6fzg 1/1 Running 0 8m25s
calico-node-l2v9z 1/1 Running 0 8m25s
calico-node-zn8ps 1/1 Running 0 8m25s
coredns-7fc97b887c-8m48p 1/1 Running 0 58m
4、Dashboard
dashboard文件 路径(源码文件路径)
./kubernetes/cluster/addons/dashboard/
#默认Dashboard只能集群内部访问,修改Service为NodePort类型,暴露到外部:
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort #新增
ports:
- port: 443
targetPort: 8443
nodePort: 30001 #新增
selector:
k8s-app: kubernetes-dashboard
#执行
kubectl apply -f dashboard.yaml
5、查看状态
[root@k8s-master01 ~]# kubectl get pods,svc -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-c74849d7-9s4jg 1/1 Running 0 10h
pod/kubernetes-dashboard-bbf598857-zsr9w 1/1 Running 4 10h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.0.0.200 <none> 8000/TCP 10h
service/kubernetes-dashboard NodePort 10.0.0.182 <none> 443:30001/TCP 10h
6、使用输出的token登录Dashboard
访问地址:https://NodeIP:30001
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')