一、CentOS 7.9 Availability Verification Kubernetes-1.25.2 Cluste
1 创建测试的资源清单
cat > /opt/kubernetes/yaml/busybox-test.yaml << EOF
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.28
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
EOF
2 部署 busybox
kubectl apply -f /opt/kubernetes/yaml/busybox-test.yaml
3 测试域名解析功能
kubectl exec busybox -n default -- nslookup kubernetes
kubectl exec busybox -n default -- nslookup kube-dns.kube-system
kubectl exec -it busybox -- sh
telnet 10.96.0.1
二、集群验证
1 使用nginx进行测试集群验证
cat > /opt/kubernetes/yaml/nginx-test.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-kube
namespace: default
labels:
app: nginx-kube
spec:
selector:
matchLabels:
app: nginx-kube
replicas: 2
template:
metadata:
labels:
app: nginx-kube
spec:
containers:
- name: nginx-kube
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
namespace: default
spec:
selector:
app: nginx-kube
type: ClusterIP
ports:
- name: nginx-svc
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: v1
kind: Namespace
metadata:
name: iyuyixyz
spec: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-xyz
namespace: iyuyixyz
labels:
app: nginx-xyz
spec:
selector:
matchLabels:
app: nginx-xyz
replicas: 1
template:
metadata:
labels:
app: nginx-xyz
spec:
containers:
- name: nginx-xyz
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc-xyz
namespace: iyuyixyz
spec:
selector:
app: nginx-xyz
type: ClusterIP
ports:
- name: nginx-svc-xyz
port: 80
targetPort: 80
protocol: TCP
EOF
2 安装
[root@kube-master01 ~]# kubectl apply -f /opt/kubernetes/yaml/nginx-test.yaml
deployment.apps/nginx-kube created
service/nginx-svc created
namespace/iyuyixyz created
deployment.apps/nginx-xyz created
service/nginx-svc-xyz created
2 查看详情
kubectl get cs,csr,node,svc,pod -A -o wide
3 在node节点访问nginx
验证Pod网络可访问性,同名称空间,不同名称空间可以使用 Pod IP 互相访问。
curl IP
4 验证Service网络可访问性,集群机器使用Service IP 可以负载均衡访问。
5 进入容器Pod内部,使用default的Pod IP访问nginx,使用default的Service IP访问nginx。
kubectl exec -it ... -n iyuyixyz -- bash
6 进入default的Pod容器内,访问跨名称空间的 Service,进行访问。Service域名:servicename.namespace
kubectl exec -it ... -n iyuyixyz -- bash
三、安装 Kubernetes-1.25.2
Installing Kubernetes-1.25.2 on CentOS 7.9:Installing Kubernetes-1.25.2 on CentOS 7.9
标签:kubectl,busybox,CentOS,Kubernetes,yaml,Cluste,nginx,1.25 From: https://www.cnblogs.com/huaxiayuyi/p/16841970.html