K8S 集群配置完成以后,可以建立各种服务和 RC
建立资源 vi lamp-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: lamp
spec:
replicas: 1
selector:
app: lamp
template:
metadata:
labels:
app: lamp
spec:
containers:
- name: lamp
image: nejidev/centos7_php_mysql_apache:php55
ports:
- containerPort: 80
kubectl create -f lamp-rc.yaml
replicationcontroller/lamp created
kubectl get rc
NAME DESIRED CURRENT READY AGE
lamp 1 1 1 67s
kubectl get pods
NAME READY STATUS RESTARTS AGE
lamp-8bgx9 1/1 Running 0 109s
建立服务 vi lamp-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: lamp
spec:
ports:
- port: 80
selector:
app: lamp
kubectl create -f lamp-svc.yaml
service/lamp created
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d22h
lamp ClusterIP 10.99.216.70 <none> 80/TCP 18s
curl -v http://10.99.216.70/
* About to connect() to 10.99.216.70 port 80 (#0)
* Trying 10.99.216.70...
* Connected to 10.99.216.70 (10.99.216.70) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 10.99.216.70
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 13 Feb 2021 03:48:24 GMT
< Server: Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/1.0.2k-fips DAV/2 PHP/5.5.38
< Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
< ETag: "11196b6-2c-3e9564c23b600"
< Accept-Ranges: bytes
< Content-Length: 44
< Content-Type: text/html
<
* Connection #0 to host 10.99.216.70 left intact
开启IP 可以访问
apiVersion: v1
kind: Service
metadata:
name: lamp
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
selector:
app: lamp
删除服务
kubectl delete -f lamp-svc.yaml
重新启动服务
kubectl create -f lamp-svc.yaml
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d22h
lamp NodePort 10.107.40.249 <none> 80:30080/TCP 70s