1. Master新增node节点方式 & 注意事项

      1. master主节点上的token钥匙

kubeadm token create --print-join-command

        在master节点上,输入此命令;输出文本可以直接粘贴到node节点上运行,此时可以连接上master主机 

      2. 如果在主机上kubeadm reset之后,需要重新kubeadm init初始化;Node节点则不需要,大部分操作都是在master主节点上完成

      3. k8s部署须知概念

        https://blog.csdn.net/ZGL_cyy/article/details/124713789

        五个重要概念:Namespace、Pod、Label、Deployment、Service

2. K8S部署实验

        根据上述的五大基本概念。  可先简单理解为docker -> Pod -> Deployment -> K8S。

        按照此逻辑,首先拥有自己的镜像images(网上拉的nginx,尚未自己编写dockerfiles自行配置)

        Deployment作为的Pod的控制器,在kubernetes中,Pod是最小的控制单元,但是kubernetes很少直接控制Pod,一般都是通过Pod控制器来完成的。

1.创建nginx Deployment

kubectl create deployment nginx --image=nginx

        此时报错,原因为:没有admin.conf的配置文件,此文件为master主节点上的文件,node节点上没有。故换到master主机上测试如上命令

 

 此时已成功创建nginx deployment

kubectl get pod

用以上命令查看pod情况

 deployment详细信息

[root@k8s-master ~]# kubectl describe deploy nginx
Name:                   nginx
Namespace:              default
CreationTimestamp:      Wed, 27 Jul 2022 15:02:09 +0800
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx
Replicas:               1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      False   MinimumReplicasUnavailable
  Progressing    False   ProgressDeadlineExceeded
OldReplicaSets:  <none>
NewReplicaSet:   nginx-8f458dc5b (1/1 replicas created)
Events:          <none>

 2.成功create deployment之后,需要使用命令expose创建service服务

        注意kubectl expose之后需要设置port和target-port(端口与容器端口)

[root@k8s-master ~]# kubectl get pod
NAME                    READY   STATUS              RESTARTS   AGE
nginx-8f458dc5b-7dkfc   0/1     ContainerCreating   0          115m
[root@k8s-master ~]# kubectl expose nginx --port=80 --target-port=8000
error: the server doesn't have a resource type "nginx"
[root@k8s-master ~]# kubectl expose deploy nginx --port=80 --target-port=8000
service/nginx exposed
[root@k8s-master ~]#

        按照此方式,无法访问此地址,原因不详。疑似主机子网网段配置问题

        换另一种方式创建service,使得外部可以访问,命令如下:

kubectl expose deploy nginx --name=svc-nginx2 --type=NodePort --port=80 --target-port=80 -n dev

[root@k8s-master ~]# kubectl get svc -o wide
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        23h   <none>
nginx        ClusterIP   10.100.188.215   <none>        80/TCP         31m   app=nginx
svc-nginx2   NodePort    10.102.123.125   <none>        80:30070/TCP   15m   app=nginx

        还是无法访问。。。。暂未查出原因

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐