标签:固定 lse service control tor 删除 health 的区别 exp
Deployment,Service,Pod是k8s最核心的3个资源对象。Role
可以定义在一个namespace
中,只能用于授予对单个命名空间中的资源访问的权限比如我们新建一个对默认命名空间中。默认的名称空间:Default
//查看名称空间
[root@master ~]# kubectl get ns
//查看名称空间详细信息
[root@master ~]# kubectl describe ns default
//创建名称空间
[root@master ~]# kubectl create ns bdqn
[root@master ~]# kubectl explain ns
[root@master ~]# vim 111-test.yaml
apiVersion: v1
kind: Namespace
metadata:
name: test
[root@master ~]# kubectl apply -f 111-test.yaml
[root@master ~]# kubectl get ns
删除资源的两种方法:
[root@master ~]# kubectl delete ns test
[root@master ~]# kubectl delete -f 111-test.yaml
Ps: namespace资源对象仅用于资源对象的隔离,并不能隔绝不同名称空间的Pod之间的的通信,那是网络策略资源的功能。
查看指定名称空间的资源可以使用--namespace或者-n选项
[root@master ~]# kubectl get pod --namespace=bdqn
No resources found.
简写:
[root@master ~]# kubectl get pod -n bdqn
No resources found.
查看本集群运行的Pod
[root@master ~]# kubectl get pod -n kube-system
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-app
image: httpd
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl get pod
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn //添加一行
spec:
containers:
- name: test-app
image: httpd
重新生成:
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
查看bdqn名称空间
[root@master ~]# kubectl get pod -n bdqn
NAME READY STATUS RESTARTS AGE
test-pod 1/1 Running 0 80s
Pod中镜像获取策略:
PS:对于标签“latest”或者是不存在,其默认策略下载及策略为“Always”,而对于其他标签的镜像,默认策略为“IfNotPresent”。
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn
spec:
containers:
- name: test-app
image: httpd
imagePullPolicy: IfNotPresent
ports:
- protocol: TCP
containerPort: 80
[root@master ~]# kubectl delete pod -n bdqn test-pod
pod "test-pod" deleted
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl get pod -n bdqn
NAME READY STATUS RESTARTS AGE
test-pod 1/1 Running 0 26s
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn
labels:
app: test-web
spec:
containers:
- name: test-app
image: httpd
imagePullPolicy: IfNotPresent
ports:
- protocol: TCP
containerPort: 90
[root@master ~]# vim svc.yaml
apiVersion: v1
kind: Service
metadata:
name: test-svc
namespace: bdqn
spec:
selector:
app: test-web
ports:
- port: 80
targetPort: 90
[root@master ~]# kubectl describe svc -n bdqn test-svc
[root@master ~]# vim healcheck.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
test: healcheck
name: healcheck
spec:
restartPolicy: OnFailure
containers:
- name: healthcheck
image: busybox
args:
- /bin/sh
- -c
- sleep 20; exit 1
[root@master ~]# kubectl apply -f healcheck.yaml
[root@master ~]# kubectl get pod -w
[root@master ~]# kubectl get pod -n kube-system
标签:固定 lse service control tor 删除 health 的区别 exp
原文地址:https://blog.51cto.com/13997536/2465657