Play with K8s ,免费使用4个小时, 但是不能外网访问,只能在网页的命令行窗口操作k8s的指令
使用说明
WARNING!!!! This is a sandbox environment. Using personal credentials is HIGHLY! discouraged. Any consequences of doing so, are completely the user's responsibilites. You can bootstrap a cluster as follows: 1. Initializes cluster master node: (初始化Master节点) kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16 2. Initialize cluster networking: (初始化集群网络) kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml 3. (Optional) Create an nginx deployment: (创建部署)
下面是执行命令后的界面返回值
kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16
Initializing machine ID from random generator. I0529 12:26:04.574068 860 version.go:251] remote version is much newer: v1.24.1; falling back to: stable-1.20 [init] Using Kubernetes version: v1.20.15 [preflight] Running pre-flight checks [WARNING Service-Docker]: docker service is not active, please run 'systemctl start docker.service' [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/ [WARNING FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist [WARNING Swap]: running with swap on is not supported. Please disable swap [preflight] The system verification failed. Printing the output from the verification: KERNEL_VERSION: 4.4.0-210-generic DOCKER_VERSION: 20.10.1 OS: Linux CGROUPS_CPU: enabled CGROUPS_CPUACCT: enabled CGROUPS_CPUSET: enabled CGROUPS_DEVICES: enabled CGROUPS_FREEZER: enabled CGROUPS_MEMORY: enabled CGROUPS_PIDS: enabled CGROUPS_HUGETLB: enabled [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03 [WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "", err: exit status 1 [preflight] Pulling images required for setting up a Kubernetes cluster [preflight] This might take a minute or two, depending on the speed of your internet connection [preflight] You can also perform this action in beforehand using 'kubeadm config images pull' [certs] Using certificateDir folder "/etc/kubernetes/pki" [certs] Generating "ca" certificate and key [certs] Generating "apiserver" certificate and key [certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local node1] and IPs [10.96.0.1 192.168.0.23] [certs] Generating "apiserver-kubelet-client" certificate and key [certs] Generating "front-proxy-ca" certificate and key [certs] Generating "front-proxy-client" certificate and key [certs] Generating "etcd/ca" certificate and key [certs] Generating "etcd/server" certificate and key [certs] etcd/server serving cert is signed for DNS names [localhost node1] and IPs [192.168.0.23 127.0.0.1 ::1] [certs] Generating "etcd/peer" certificate and key [certs] etcd/peer serving cert is signed for DNS names [localhost node1] and IPs [192.168.0.23 127.0.0.1 ::1] [certs] Generating "etcd/healthcheck-client" certificate and key [certs] Generating "apiserver-etcd-client" certificate and key [certs] Generating "sa" key and public key [kubeconfig] Using kubeconfig folder "/etc/kubernetes" [kubeconfig] Writing "admin.conf" kubeconfig file [kubeconfig] Writing "kubelet.conf" kubeconfig file [kubeconfig] Writing "controller-manager.conf" kubeconfig file [kubeconfig] Writing "scheduler.conf" kubeconfig file [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Starting the kubelet [control-plane] Using manifest folder "/etc/kubernetes/manifests" [control-plane] Creating static Pod manifest for "kube-apiserver" [control-plane] Creating static Pod manifest for "kube-controller-manager" [control-plane] Creating static Pod manifest for "kube-scheduler" [etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests" [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s [apiclient] All control plane components are healthy after 10.503349 seconds [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace [kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster [upload-certs] Skipping phase. Please see --upload-certs [mark-control-plane] Marking the node node1 as control-plane by adding the labels "node-role.kubernetes.io/master=''" and "node-role.kubernetes.io/control-plane='' (deprecated)" [mark-control-plane] Marking the node node1 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule] [bootstrap-token] Using token: 0ydxaf.43r8a0990ogp8l83 [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster [bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace [addons] Applied essential addon: CoreDNS [addons] Applied essential addon: kube-proxy 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://kubernetes.io/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.0.23:6443 --token 0ydxaf.43r8a0990ogp8l83 \ --discovery-token-ca-cert-hash sha256:020d14f0a1797b92376c3cd4925df2e0c61eafa6f6350fba6891a84dc4c80ea1
注意上面返回值的最后一句, 这句是用来往集群里加worker节点的.(token 24小时有效)
设置网络
kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml
configmap/kube-router-cfg created daemonset.apps/kube-router created serviceaccount/kube-router created clusterrole.rbac.authorization.k8s.io/kube-router created clusterrolebinding.rbac.authorization.k8s.io/kube-router created
新建一个Node, 然后运行这句, 加入集群
kubeadm join 192.168.0.23:6443 --token 0ydxaf.43r8a0990ogp8l83 \ --discovery-token-ca-cert-hash sha256:020d14f0a1797b92376c3cd4925df2e0c61eafa6f6350fba6891a84dc4c80ea1
然后在Master里查询kubectl get nodes
[node1 ~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION node1 Ready control-plane,master 22m v1.20.1 [node1 ~]$ [node1 ~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION node1 Ready control-plane,master 57m v1.20.1 node2 Ready <none> 34s v1.20.1
部署宠物医院的应用(镜像已经放在dockerHub上面)
kubectl apply -f https://raw.githubusercontent.com/spring2go/spring-petclinic-msa/master/k8s/local/gateway-svc.yml kubectl apply -f https://raw.githubusercontent.com/spring2go/spring-petclinic-msa/master/k8s/local/customers-svc.yml kubectl apply -f https://raw.githubusercontent.com/spring2go/spring-petclinic-msa/master/k8s/local/vets-svc.yml kubectl apply -f https://raw.githubusercontent.com/spring2go/spring-petclinic-msa/master/k8s/local/visits-svc.yml kubectl apply -f https://raw.githubusercontent.com/spring2go/spring-petclinic-msa/master/k8s/local/web-app.yml
查看部署成功是否成功,检查Services
node1 ~]$ k get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE customers ClusterIP 10.111.236.10 <none> 8080/TCP 34s gateway NodePort 10.110.17.106 <none> 8080:31080/TCP 45s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3m47s vets ClusterIP 10.110.47.245 <none> 8080/TCP 25s visits ClusterIP 10.108.141.95 <none> 8080/TCP 17s web ClusterIP 10.109.65.250 <none> 8080/TCP 6s [node1 ~]$ curl http://10.110.17.106:8080 <!DOCTYPE html> <html ng-app="petClinicApp" lang="en">
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示