sudo tee ./images.sh <<-'EOF' #!/bin/bash images=( kube-apiserver:v1.20.9 kube-proxy:v1.20.9 kube-controller-manager:v1.20.9 kube-scheduler:v1.20.9 coredns:1.7.0 etcd:3.4.13-0 pause:3.2 ) for imageName in${images[@]} ; do docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName done EOF chmod +x ./images.sh && ./images.sh
2、初始化主节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
解决一个问题: [init] Using Kubernetes version: v1.20.9 [preflight] Running pre-flight checks [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.11. Latest validated version: 19.03 [WARNING Hostname]: hostname "k8s-master" could not be reached [WARNING Hostname]: hostname "k8s-master": lookup k8s-master on 183.60.82.98:53: no such host [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service' error execution phase preflight: [preflight] Some fatal errors occurred: [ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1 [preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...` To see the stack trace of this error execute with --v=5 or higher
解决办法: vim /etc/sysctl.conf net.ipv4.ip_forward = 1 重启网络 service network restart
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. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root:
You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root:
Then you can join any number of worker nodes by running the following on each as root: -- 添加node节点 kubeadm join cluster-endpoint:6443 --token pzft0w.mqm67hcg27s1aeuw \ --discovery-token-ca-cert-hash sha256:48c57808cbef8582c3c90383d06f279c2768c617eaef8cd69190fe9457709bc8
1 2 3 4 5 6 7 8 9 10
#查看集群所有节点 kubectl get nodes
#根据配置文件,给集群创建资源 kubectl apply -f xxxx.yaml
#查看集群部署了哪些应用? docker ps === kubectl get pods -A # 运行中的应用在docker里面叫容器,在k8s里面叫Pod kubectl get pods -A
# 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: containers: -name:kubernetes-dashboard image:kubernetesui/dashboard:v2.3.1 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