• k8s系列---kubectl基础


    kubectl get pods  查看所有pods

    kubectl  get  services  查看services

    kubectl replace --filename=myweb-rc.yaml  根据该yaml更新pod可以修改副本数为0,删除pod

    docker ps -a   查看所有docker容器

    docker  attach 容器名     进入容器内

    kubectl  describe pod pod名字   查看该pod的详细信息

     http://blog.itpub.net/28916011/viewspace-2213957/

    k8s
    master/node
    	master : API Server ,Scheduler,Controller-Manager
    	node : kubelet,docker,kube-proxy
    
    Pod:
    	自主式Pod
    	控制器管理的Pod
    		ReplicationController(RC)
    		ReplicaSet
    		Deployment
    		StatefulSet
    		DaemonSet
    		Job,CronJob
    
    环境
    	master,etcd:172.18.0.67
    	node1:172.18.0.68
    	node2:172.18.0.69
    前提;
    	1:基于主机名通信:/etc/hosts
    	2:时间同步
    	3:关闭firewall和iptables.service
    	OS:Centos7.3 1611
    		   yum -y install ntp
    		   systemctl start ntpd
    		   systemctl enable ntpd
    		   systemctl stop firewalld
    		   systemctl disable firewalld
    		   
    		   vim /etc/hosts
    				172.16.100.64   master
    				172.16.100.65   node1
    				172.16.100.66   node2
    				
    		   wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    		   [root@master yum.repos.d]# cat kubernets.repo 
    				[kubernetes]
    				name=Kubernetes Repo
    				baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    				gpgcheck=0
    			scp kubernets.repo  docker-ce.repo  node1:/etc/yum.repos.d
    			scp kubernets.repo  docker-ce.repo  node2:/etc/yum.repos.d
    			yum install docker-ce kubelet kubeadm  kubectl
    
    	
    	
    	
    	
    		   vim /usr/lib/systemd/system/docker.service 
    				[service]增加
    				Environment="HTTPS_PROXY=http://www.ik8s.io:10080"
    				Environment="NO_PROXY=127.0.0.0/8,172.16.0.0/16"
    		   systemctl daemon-reload
    		   systemctl restart docker
    		   systemctl status docker
    		   docker info
    		   确保下面两个为1
    		   [root@master ~]# cat /proc/sys/net/bridge/bridge-nf-call-ip6tables 
    			1
    		   [root@master ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables 
    			1
    	
    	
    		systemctl status kubelet有出错信息,需要停掉kubelet,然后设置开机启动,docker也设成开机启动,出不出错都要操作,后面初始化出错了
    		然后初始化
    		初始化的时候出错。因为swap选项
    		kubeadm  init --help 查看帮助信息, --kubernetes-version string 指定版本,默认为当前稳定版
    		kubeadm  init --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
    		如果出错有swap,不支持。需要的操作:
    		vim /etc/sysconfig/kubelet
    		KUBELET_EXTRA_ARGS="--fail-swap-on=false"
    		然后重新初始化,添加忽略参数
    	    kubeadm  init --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
    		妈逼的代理不成功,总下载失败,最后搜到可以这么干--image-repository registry.aliyuncs.com/google_containers 配置文件取消掉代理,重新reload,重启docker
    		kubeadm  init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.13.1  --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
    		安装完成结尾会有token和哈希码,一定要保存下来。不然以后就麻烦了,就是类似下面这串。
    		kubeadm join 172.16.100.64:6443 --token yqzclr.ztxgcumdlqzjbpl4 --discovery-token-ca-cert-hash sha256:b5119e9530e8bd01b0317e19f3ca14835ad457f3d33a5de963e7a8fa33f3a541
    		
    		
    		接下来等master安装完回到master操作
    		[root@master ~]#  mkdir -p $HOME/.kube
    	    [root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    		
    		[root@master ~]# kubectl get cs     查询组件状态健康信息
    		
    		二:部署网络插件flannel   https://github.com/coreos/flannel
    		kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    		部署完成后稍等一分钟
    		kubectl get nodes  可以发现master状态Ready了。
    		kubectl get pods -n kube-system   会发现flannel的pod
    		
    		客户端node操作
    		yum -y install docker-ce kubelet kubeadm
    		
    		master执行 拷贝配置文件到两台node上
            scp /usr/lib/systemd/system/docker.service node1:/usr/lib/systemd/system/docker.service
            scp /etc/sysconfig/kubelet node1:/etc/sysconfig/kubelet
    		
    		客户端node操作
    		yum -y install docker-ce kubelet kubeadm
    	    systemctl enable docker kubelet
    		systemctl daemon-reload
    	    systemctl start docker 
    	    docker info
    		加入到master,就是之前复制的那一串,然后加上忽略Swap
    	    kubeadm join 172.16.100.64:6443 --token yqzclr.ztxgcumdlqzjbpl4 --discovery-token-ca-cert-hash sha256:b5119e9530e8bd01b0317e19f3ca14835ad457f3d33a5de963e7a8fa33f3a541 --ignore-preflight-errors=Swap
    		
    		以上安装全部完成
    		
    		
    		
    		
    安装配置
    	1:etcd cluster 仅master节点
    	2:flannel 集群的所有节点
    	3:配置k8s的master 仅master节点
    		kubernets-master
    		启动的服务:
    			kube-apiserver kube-scheduler kube-controller-manager
    	4:配置k8s的各Node节点
    		kubernets-node
    		
    		先设定启动docker服务
    		启动k8s的服务:
    			kube-proxy,kubelte
    			
    kubeadm
    	1:master,node:安装kubelet kubeadm docker
    	2:master:kubeadm init
    

      

     day2      http://blog.itpub.net/28916011/viewspace-2213957/

    k8s相关介绍
    
    资源:对象
    	workload:Pod,ReplicaSet,Deployment,StatefulSet,Job,Cronjob...
    	服务发现及均衡:Service,Ingress...
    	配置与存储:Volume,CSI,
    	    ConfigMap,Secret
    	集群级资源:
    		NameSpace,Node,Role,ClusterRole,RoleBind,ClusterRoleBind
    	元数据型资源
    		HPA,PodTemplate,LimitRange,
    	
    		
    创建资源的配置清单
    	apiVersion: group/version
    		$ kubectl api-version
    	kind:资源类别
    	metadata:元数据
    		name
    		namespace
    		labels
    		annotations
    		每个资源的引用PATH
    			/api/GROUP/VERSION/namespace/NAMESPACE/TYPE/NAME
    			
    	spec: 期望状态 disired state
    	status:当前状态  current state,本字段由k8s集群维护
    	
    		
    	Pod 资源
    		spec.containers <[]object>
    		
    		- name <string>
    		  image <string>   //如果是latest标签,就会一直下载,但是下面如果改成ifnotpresent 那就不会一直下不会使用默认的aways
    		  imagePullPolicy <string>
    		    Always,Never,IfNotPresent    //always总是下载,Never不下载,ifnotpresent 如果不存在就下载
    		  
    		  
    		  
    标签操作
    	查询某个pod,node标签,
    	[root@master k8syaml]# kubectl get pods pod-demo --show-labels
    	查询app标签的pod
    	kubectl get pods -l app --show-labels  
    	添加标签为某个pod
    	kubectl label pods pod-demo relase=beata
    	修改某个标签的值
    	kubectl label pods pod-demo relase=stable --overwrite
    	
    	标签选择器
    		等值关系:=,==,!=
    		集合关系:key in (value1,value2);key notin (value1,value2)
    		
    	查询relase等于stable,并且app=myapp标签的pod
    	[root@master k8syaml]# kubectl get pods -l relase=stable,app=myapp	
    	基于集合的查询,relase如果等于stable或者beta的pod
    	[root@master k8syaml]# kubectl get pods -l "relase in (stable,beta)"
    	
    	基于节点的
    	[root@master k8syaml]# kubectl get nodes  --show-labels
    	NAME     STATUS   ROLES    AGE     VERSION   LABELS
    	master   Ready    master   2d22h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
    	node1    Ready    <none>   2d20h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node1
    	node2    Ready    <none>   2d20h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node2
    	[root@master k8syaml]# kubectl label nodes node1 disktype=ssd
    	node/node1 labeled
    	[root@master k8syaml]# kubectl get nodes  --show-labels
    	NAME     STATUS   ROLES    AGE     VERSION   LABELS
    	master   Ready    master   2d22h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
    	node1    Ready    <none>   2d20h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/hostname=node1
    	node2    Ready    <none>   2d20h   v1.13.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node2
    
    
    	
    	nodeSelector: 指定pod运行在标签哪个节点,下面是运行在标签为disktype: ssd的nod上
    	[root@master k8syaml]# cat demo.yaml 
    	apiVersion: v1
    	kind: Pod
    	metadata:
    		name: pod-demo
    		namespace: default
    		labels:
    			app: myapp
    			tier: forntend
    	spec:
    		containers:
    		- name: myapp
    		  image: ikubernetes/myapp:v1
    		- name: busybox
    		  image: busybox:latest
    		  command: 
    		  - "/bin/sh"
    		  - "-c"
    		  - "sleep 3600"
    		nodeSelector:
    			disktype: ssd
    			
    			
    	
    	nodeName:运行在指定的节点上
    	annotations:与label不同的地方在于,它不能用于挑选资源对象,仅用于为对象提供“元数据”
    	[root@master k8syaml]# vim demo.yaml 
    	apiVersion: v1
    	kind: Pod
    	metadata:
    		name: pod-demo
    		namespace: default
    		labels:
    			app: myapp
    			tier: forntend
    		annotations:
    			lihongxing.com/created-by: cluster admin
    	spec:
    		containers:
    		- name: myapp
    		  image: ikubernetes/myapp:v1
    		- name: busybox
    		  image: busybox:latest
    		  command:
    		  - "/bin/sh"
    		  - "-c"
    		  - "sleep 3600"
    
    		nodeSelector:
    			disktype: ssd
    			
    	以上会添加lihongxing.com/created-by: cluster admin的annotations资源注解,用describe可以查看到
    	[root@master k8syaml]# kubectl describe pods pod-demo
    
    		  
    Pod生命周期:http://blog.itpub.net/28916011/viewspace-2213957/
    	状态:Pending/Running/Failed/Succeeded/Unknown
    	Pod生命周期的重要行为:
    		初始化容器
    		容器探测:
    			liveness 存活性探针
    			readiness  就绪性探针
    	restartpolicy 重启策略:
    		Always,OnFailure,Never,Default to Always
    	探针类型三种:
    		ExecAction,TcpSocketAction,HttpGetAction
    		
    	[root@master k8syaml]# vim liveness.yaml
    	apiVersion: v1
    	kind: Pod
    	metadata:
    		name: liveness-exec.pod
    		namespace: default
    	spec:
    		containers:
    		- name: liveness-exec-container
    		  image: busybox:latest
    		  imagePullPolicy: IfNotPresent
    		  command: ["/bin/sh","-c","toch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 3600"]
    		  livenessProbe:
    			  exec:
    				  command: ["test","-e","/tmp/healthy"]
    			  initialDelaySeconds: 1
    			  periodSeconds: 3	
    		
    

      

     

  • 相关阅读:
    textarea组件
    switch组件
    slider组件
    radio组件
    picker-view组件
    picker组件 label组件讲解
    weui 框架
    微信小程序 input 组件
    在php中获取 数据库的内容,返回到页面
    微信小程序 form 组件
  • 原文地址:https://www.cnblogs.com/dribs/p/9082458.html
Copyright © 2020-2023  润新知