虚拟机创建三个节点这里略过.
k8s installset -x#根据规划设置主机名(在3台机上分别运行)hostnamectl set-hostname master01 hostnamectl set-hostname node01 hostnamectl set-hostname node02#关闭防火墙ufw disable#关闭swapswapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab#安装 dockersudo apt-get install -y docker sudo apt-get install -y docker.io docker --version systemctl start docker apt-get install -y apt-transport-https apt-get install -y curl# kubeadm init 默认会去google拉镜像,所以换了阿里的源,前面docker是系统默认的.curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main EOFapt-get update# master上运行apt-get install -y kubelet kubeadm kubectl# node上运行apt-get install -y kubelet kubeadm apt-get install -y ethtool apt-get install -y socat apt-get install -y conntrack# checkkubeadm version# 配置docker cgroupdriver (与kubelet要一致)cat <<EOF >/etc/docker/daemon.json {"exec-opts": ["native.cgroupdriver=systemd"]} EOFsystemctl restart docker systemctl start kubeletexport KUBECONFIG=/etc/kubernetes/admin.conf# master 上运行kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16#Your Kubernetes control-plane has initialized successfully!##To start using your cluster, you need to run the following as a regular user:## mkdir -p $HOME/.kube# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config# sudo chown $(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.#Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:# https:///docs/concepts/cluster-administration/addons/##Then you can join any number of worker nodes by running the following on each as root:##kubeadm join 192.168.137.6:6443 --token vzcxza.bhcs335r92677g3i \# --discovery-token-ca-cert-hash sha256:72b820c8f2dd7606ddbf6a155fadb57e0f266c15bb39c7f41de61cc605f6f962 # kubeadm init 通过给的 kubeadm join 将node 加入master 节点kubeadm join 192.168.137.6:6443 --token vzcxza.bhcs335r92677g3i --discovery-token-ca-cert-hash sha256:72b820c8f2dd7606ddbf6a155fadb57e0f266c15bb39c7f41de61cc605f6f962# K8S在kubeadm init以后查询kubeadm join# kubeadm token create --print-join-commandset +x 到这1个master节点2个node节点的k8s就搭好了 root@master01:~/k8s# kubectl get nodes -ANAME STATUS ROLES AGE VERSION master01 Ready control-plane,master 4d17h v1.23.5node01 Ready <none> 2d v1.23.5node02 Ready <none> 2d v1.23.5 部署hello world 应用
package mainimport ( "net/http" "flag" log "github.com/sirupsen/logrus" "github.com/gin-gonic/gin")func entry(c *gin.Context) { c.String(http.StatusOK, "hello !") }func main() { flag.Parse() var ( ) log.Info("hello serv start ...") engine := gin.Default() engine.GET("/entry", entry) engine.Run("0.0.0.0:8868") }
FROM golang:1.17.2-stretchENV GOPROXY=http://WORKDIR $GOPATH/src/ADD ./bin $GOPATH/src/binADD ./source $GOPATH/src/RUN go env -w GOSUMDB=offWORKDIR $GOPATH/src/RUN go build -o /usr/local/bin/engineCMD ["/usr/local/bin/engine"]
apiVersion: apps/v1kind: Deploymentmetadata: name: hello-minikubesspec: selector: matchLabels: app: myweb replicas: 2 template: metadata: labels: app: myweb spec: containers: - name: hello-minikubes image: ailumiyana/minikube-hello:latest ports: - containerPort: 8868 protocol: TCP---apiVersion: v1kind: Servicemetadata: name: mywebspec: type: NodePort ports: - port: 8868 targetPort: 8868 nodePort: 31314 selector: app: myweb kubectl apply -f hello.yml F5几下,检查两个节点,好像都有流量,还不知道什么策略,慢慢研究~ 今天先到这~ issue 汇总node 一直处理NotReady状态
好像是没网络插件,搜索尝试手动添加 flannel 镜像和 cni 配置 后解决 docker pull quay.io/coreos/flannel:v0.11.0-amd64mkdir -p /etc/cni/net.d/cat <<EOF> /etc/cni/net.d/10-flannel.conf {"name":"cbr0","type":"flannel","delegate": {"isDefaultGateway": true}} EOFmkdir /usr/share/oci-umount/oci-umount.d -pmkdir /run/flannel/cat <<EOF> /run/flannel/subnet.env FLANNEL_NETWORK=172.100.0.0/16 FLANNEL_SUBNET=172.100.1.0/24 FLANNEL_MTU=1450 FLANNEL_IPMASQ=true EOF https://raw./coreos/flannel/v0.11.0/Documentation/kube-flannel.yml 重启系统后虚拟机的网络不通这个也是个坑,最后在网络连接里面,重新关闭开启vmnet1的网络共享后好了. |
|