Resource | Version |
Host OS | Ubuntu 20.04 |
Kubernetes | v1.19.10 |
deployment tool | kubeadm |
CRI | containerd 1.4.4 |
cgroup driver | systemd |
apt update && apt upgrade -yapt install vim htop net-tools build-essential openssh-server axel tmux
apt-get remove docker docker-engine docker.io containerd runcapt-get updateapt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-commoncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -apt-key fingerprint 0EBFCD88add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable"apt-get update
CONTAINERD_VER="1.4.4-1"apt-get install -y containerd.io=${CONTAINERD_VER}
apt-mark hold containerd.io
https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd
cat <
sudo mkdir -p /etc/containerdcontainerd config default | sudo tee /etc/containerd/config.toml
vi /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] ... [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] SystemdCgroup = true # add this
sudo systemctl daemon-reloadsudo systemctl restart containerd
swapoff -a
要永久禁用交换,请编辑 /etc/fstab
modprobe br_netfilter
cat <
apt-get update && apt-get install -y apt-transport-https curlcurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -cat <
cat > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf << EOF# Note: This dropin only works with kubeadm and kubelet v1.11+[Service]Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamicallyEnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.EnvironmentFile=-/etc/default/kubeletExecStart=# ExecStart=/usr/bin/kubeletEnvironment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"ExecStart=/usr/bin/kubeletEOF
K_VER="v1.19.10"
$ kubeadm config images pull \--image-repository="k8s.gcr.io" \--kubernetes-version=${K_VER}W0429 15:48:45.321686 10570 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io][config/images] Pulled k8s.gcr.io/kube-apiserver:v1.19.10[config/images] Pulled k8s.gcr.io/kube-controller-manager:v1.19.10[config/images] Pulled k8s.gcr.io/kube-scheduler:v1.19.10[config/images] Pulled k8s.gcr.io/kube-proxy:v1.19.10[config/images] Pulled k8s.gcr.io/pause:3.2[config/images] Pulled k8s.gcr.io/etcd:3.4.13-0[config/images] Pulled k8s.gcr.io/coredns:1.7.0
kubeadm init \--image-repository=k8s.gcr.io \--kubernetes-version=${K_VER} \--pod-network-cidr=10.244.0.0/16 \--service-cidr=10.96.0.0/12 \--control-plane-endpoint="$(hostname)" \--apiserver-advertise-address=0.0.0.0 \--cri-socket="/run/containerd/containerd.sock"
echo -e "
alias k=kubectl" >> ${HOME}/.bashrcecho "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ${HOME}/.bashrcsource ${HOME}/.bashrc
为 Pod 网络安装Flannel v0.13.0
wget "https://raw.githubusercontent.com/flannel-io/flannel/v0.13.0/Documentation/kube-flannel.yml"
kubectl apply -f ./kube-flannel.yml
$ kubectl get po -n kube-systemNAME READY STATUS RESTARTS AGEcoredns-f9fd979d6-v8dgp 1/1 Running 0 29mcoredns-f9fd979d6-wt88m 1/1 Running 0 29metcd-tom-k8s 1/1 Running 0 29mkube-apiserver-tom-k8s 1/1 Running 0 29mkube-controller-manager-tom-k8s 1/1 Running 0 29mkube-flannel-ds-5jqww 1/1 Running 0 26mkube-proxy-kdxtr 1/1 Running 0 29mkube-scheduler-tom-k8s 1/1 Running 0 29m
$ kubectl taint nodes --all node-role.kubernetes.io/master-node/tom-k8s untainted
cat > helloworld.yaml << EOFapiVersion: v1kind: Namespacemetadata: name: helloworld---apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: helloworld namespace: helloworldspec: rules: - http: paths: - pathType: Prefix path: /helloworld backend: service: name: helloworld port: number: 8080---apiVersion: apps/v1kind: Deploymentmetadata: name: helloworld namespace: helloworldspec: selector: matchLabels: run: helloworld replicas: 1 template: metadata: labels: run: helloworld spec: containers: - name: helloworld image: gcr.io/google-samples/node-hello:1.0 ports: - containerPort: 8080 protocol: TCP---apiVersion: v1kind: Servicemetadata: name: helloworld namespace: helloworldspec: ports: - nodePort: 31215 port: 8080 protocol: TCP targetPort: 8080 selector: run: helloworld type: NodePortEOF
访问服务
kubectl apply -f ./helloworld.yaml$ curl 0.0.0.0:31215Hello Kubernetes!
删除应用程序
kubectl delete -f ./helloworld.yaml
kubeadm reset -f
Kubernetes
rm -rf ${HOME}/.kubesudo -irm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetesrm -rf ${HOME}/.kubeiptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -Xifconfig cni0 downip link delete cni0ifconfig flannel.1 downip link delete flannel.1rm -rf /var/lib/cni/rm -f /etc/cni/net.d/*
reboot
留言与评论(共有 0 条评论) “” |