Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user: # 初始化成功后操作1 mkdir -p $HOME/.kube sudocp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudochown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. # 初始化成功后操作2 Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root: # 初始化成功后操作3 kubeadm join 192.168.58.135:6443 --token lqsu8e.slm32auk92zge8uv \ --discovery-token-ca-cert-hash sha256:fd9eb078dbe1e64d83463c78879496e993eb1c7b4b586ee17ec9e130bd158e01 [root@k8smaster ~]#
[root@k8smaster ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml The connection to the server raw.githubusercontent.com was refused - did you specify the right host or port?
[root@SqaMaster1 kubernetes]# kubectl get node NAME STATUS ROLES AGE VERSION sqamaster1 Ready control-plane,master 2d20h v1.23.6 sqanode1 Ready <none> 2d20h v1.23.6 sqanode2 Ready <none> 2d20h v1.23.6 sqanode3 NotReady <none> 26s v1.23.6 [root@SqaMaster1 kubernetes]#
新节点加入集群时可能出现错误,可使用以下命令尝试之后再次加入
1
[root@SqaMaster1 kubernetes]# kubeadm reset
Kubernetes DashBoard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: type: NodePort # new ports: - port: 443 targetPort: 8443 nodePort: 30009 # new selector: k8s-app: kubernetes-dashboard
---
下载yaml文件并运行,以上为具体修改内容,完整文件在下方
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@k8smaster dashboard]# kubectl create -f dashboard-recommended.yaml namespace/kubernetes-dashboard created serviceaccount/kubernetes-dashboard created service/kubernetes-dashboard created secret/kubernetes-dashboard-certs created secret/kubernetes-dashboard-csrf created secret/kubernetes-dashboard-key-holder created configmap/kubernetes-dashboard-settings created role.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created deployment.apps/kubernetes-dashboard created service/dashboard-metrics-scraper created deployment.apps/dashboard-metrics-scraper created [root@k8smaster dashboard]#
查看namespace为kubernetes-dashboard下的资源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@k8smaster dashboard]# kubectl get pod,svc -n kubernetes-dashboard -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/dashboard-metrics-scraper-6f669b9c9b-l8tkp 0/1 ContainerCreating 0 20s <none> k8snode1 <none> <none> pod/kubernetes-dashboard-758765f476-94cz2 0/1 ContainerCreating 0 21s <none> k8snode1 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/dashboard-metrics-scraper ClusterIP 10.110.173.13 <none> 8000/TCP 21s k8s-app=dashboard-metrics-scraper service/kubernetes-dashboard NodePort 10.104.63.91 <none> 443:30009/TCP 21s k8s-app=kubernetes-dashboard [root@k8smaster dashboard]# [root@k8smaster dashboard]# kubectl get pod,svc -n kubernetes-dashboard -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/dashboard-metrics-scraper-6f669b9c9b-l8tkp 1/1 Running 0 99s 10.244.1.12 k8snode1 <none> <none> pod/kubernetes-dashboard-758765f476-94cz2 1/1 Running 0 100s 10.244.1.11 k8snode1 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/dashboard-metrics-scraper ClusterIP 10.110.173.13 <none> 8000/TCP 100s k8s-app=dashboard-metrics-scraper service/kubernetes-dashboard NodePort 10.104.63.91 <none> 443:30009/TCP 100s k8s-app=kubernetes-dashboard
# Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
--- kind:Deployment apiVersion:apps/v1 metadata: labels: k8s-app:kubernetes-dashboard name:kubernetes-dashboard namespace:kubernetes-dashboard spec: replicas:1 revisionHistoryLimit:10 selector: matchLabels: k8s-app:kubernetes-dashboard template: metadata: labels: k8s-app:kubernetes-dashboard spec: securityContext: seccompProfile: type:RuntimeDefault containers: -name:kubernetes-dashboard image:kubernetesui/dashboard:v2.7.0 imagePullPolicy:Always ports: -containerPort:8443 protocol:TCP args: ---auto-generate-certificates ---namespace=kubernetes-dashboard # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. # - --apiserver-host=http://my-address:port volumeMounts: -name:kubernetes-dashboard-certs mountPath:/certs # Create on-disk volume to store exec logs -mountPath:/tmp name:tmp-volume livenessProbe: httpGet: scheme:HTTPS path:/ port:8443 initialDelaySeconds:30 timeoutSeconds:30 securityContext: allowPrivilegeEscalation:false readOnlyRootFilesystem:true runAsUser:1001 runAsGroup:2001 volumes: -name:kubernetes-dashboard-certs secret: secretName:kubernetes-dashboard-certs -name:tmp-volume emptyDir: {} serviceAccountName:kubernetes-dashboard nodeSelector: "kubernetes.io/os":linux # Comment the following tolerations if Dashboard must not be deployed on master tolerations: -key:node-role.kubernetes.io/master effect:NoSchedule