在Kubernetes下将pod启动到指定node节点
1、以tomcat为例的yaml文件如下:[root@k8s-node1 yaml_file]# cat 1.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: tomcatspec:replicas: 1selector:matchLabels:app: tomcatminRead...
·
1、以tomcat为例的yaml文件如下:
[root@k8s-node1 yaml_file]# cat 1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
minReadySeconds: 1
progressDeadlineSeconds: 60
revisionHistoryLimit: 5
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
name: tomcat
labels:
app: tomcat
spec:
nodeSelector: #node节点标签选择器
disk: ssd #node节点标签内容
containers:
- name: tomcat
image: tomcat:8
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 45
periodSeconds: 20
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 45
periodSeconds: 20
volumeMounts:
- name: tz-config
mountPath: /etc/localtime
volumes:
- name: tz-config
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
---
apiVersion: v1
kind: Service
metadata:
name: tomcat
spec:
type: NodePort
ports:
- port: 8080
selector:
app: tomcat
2、创建node节点的labels
2.1、查看node节点名称
[root@k8s-node1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
192.168.29.176 Ready <none> 17d v1.10.3
192.168.29.182 Ready <none> 17d v1.10.3
2.2、添加node节点labels
kubectl label nodes <node-name> <label-key>=<label-value> #添加label语法
[root@k8s-node1 ~]# kubectl label node 192.168.29.182 disk=ssd
node "192.168.29.182" labeled
2.3、查看pod运行状态
[root@k8s-node1 yaml_file]# kubectl get pod -o wide
tomcat-6c5598cd87-qwm4b 1/1 Running 0 18m 10.2.11.52 192.168.29.182
2.4、修改node节点标签需要添加–overwrite参数
[root@k8s-node1 ~]# kubectl label node 192.168.29.182 disk=hdd --overwrite
2.5、查看node节点标签
[root@k8s-node1 ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
192.168.29.176 Ready <none> 17d v1.10.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.29.176
192.168.29.182 Ready <none> 17d v1.10.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/hostname=192.168.29.182
2.6、删除node节点标签
kubectl label nodes <node-name> <label-key>- #删除label语法
[root@k8s-node1 ~]# kubectl label node 192.168.29.182 disk-
node "192.168.29.182" labeled
2.7、查看删除后的结果
[root@k8s-node1 ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
192.168.29.176 Ready <none> 17d v1.10.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.29.176
192.168.29.182 Ready <none> 17d v1.10.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.29.182
更多推荐
已为社区贡献45条内容
所有评论(0)