一、pod
pod资源:至少由两个容器组成,pod基础容器和业务容器组成(最多1+4)
pod是k8s最小的资源单位
pod配置文件1拖2:
[root@k8s-master pod]# cat k8s_pod2.yml
apiVersion: v1
kind: Pod
metadata:
name: test
labels:
app: web
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/nginx:1.13
ports:
- containerPort: 80
- name: alpine
image: 10.0.0.11:5000/alpine:latest
command: ["sleep","1000"]
[root@k8s-master pod]# kubectl create -f k8s_pod2.yml
1拖2完成
[root@k8s-master pod]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx 1/1 Running 0 1h 172.18.48.2 10.0.0.13
test 2/2 Running 0 2m 172.18.65.3 10.0.0.12
===================
replicationController == rc
rc:保证指定数量的pod始终存活,rc通过标签选择器来关联pod
kubectl create -f xxx.yaml
kubectl get pod|rc
kubectl describe pod nginx
kubectl delete pod nginx 或者kubectl delete -f xxx.yaml
kubectl edit pod nginx
创建一个rc
mkdir rc
cd rc/
[root@k8s-master rc]# cat k8s_rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 5 #副本5
selector:
app: myweb
template: #模板
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: 10.0.0.11:5000/nginx:1.13
ports:
- containerPort: 80
kubectl create -f k8s_rc.yml
[root@k8s-master rc]# kubectl get replicationcontroller
NAME DESIRED CURRENT READY AGE
nginx 5 5 5 42s
[root@k8s-master rc]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 1h
nginx-0591k 1/1 Running 0 2m
nginx-c62z9 1/1 Running 0 2m
nginx-cmhdp 1/1 Running 0 2m
nginx-gdhz0 1/1 Running 0 2m
nginx-hb6fv 1/1 Running 0 2m
test 2/2 Running 2 37m
删除测试
[root@k8s-master rc]# kubectl delete pod nginx-0591k
pod "nginx-0591k" deleted
[root@k8s-master rc]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx 1/1 Running 0 1h 172.18.48.2 10.0.0.13
nginx-c62z9 1/1 Running 0 3m 172.18.65.5 10.0.0.12
nginx-cmhdp 1/1 Running 0 3m 172.18.65.4 10.0.0.12
nginx-gdhz0 1/1 Running 0 3m 172.18.48.4 10.0.0.13
nginx-hb6fv 1/1 Running 0 3m 172.18.48.3 10.0.0.13
nginx-q19qw 1/1 Running 0 29s 172.18.65.6 10.0.0.12
test 2/2 Running 2 38m 172.18.65.3 10.0.0.12
查看标签
[root@k8s-master rc]# kubectl get pod -o wide --show-labels
NAME READY STATUS RESTARTS AGE IP NODE LABELS
nginx 1/1 Running 0 1h 172.18.48.2 10.0.0.13 app=web
nginx-c62z9 1/1 Running 0 8m 172.18.65.5 10.0.0.12 app=myweb
nginx-cmhdp 1/1 Running 0 8m 172.18.65.4 10.0.0.12 app=myweb
nginx-gdhz0 1/1 Running 0 8m 172.18.48.4 10.0.0.13 app=myweb
nginx-hb6fv 1/1 Running 0 8m 172.18.48.3 10.0.0.13 app=myweb
nginx-q19qw 1/1 Running 0 5m 172.18.65.6 10.0.0.12 app=myweb
test 2/2 Running 2 43m 172.18.65.3 10.0.0.12 app=web
[root@k8s-master rc]# kubectl get rc -o wide
NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
nginx 5 5 5 9m myweb 10.0.0.11:5000/nginx:1.13 app=myweb
编辑pod
修改标签
[root@k8s-master rc]# kubectl edit pod nginx
少了一个pod
[root@k8s-master rc]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 1h
nginx-c62z9 1/1 Running 0 12m
nginx-cmhdp 1/1 Running 0 12m
nginx-gdhz0 1/1 Running 0 12m
nginx-hb6fv 1/1 Running 0 12m
-----------------------------------------------------
有问题请加博主微信进行沟通!
全部评论