>我正在尝试在kubernetes
上创建一个服务,但尽管没有打印错误,但我无法列出该服务;
与minikube
一起在本地工作
*$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h
/home/pkara/Workspace/gitlab/my-minikube
*$ kubectl apply -f mydb.yaml
service/mydatabase unchanged
/home/pkara/Workspace/gitlab/my-minikube
*$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h
以下是使用的清单:
---
apiVersion: v1
kind: Service
metadata:
name: mydatabase
namespace: esa-local-dev
labels:
app: mydatabase
spec:
ports:
- name: mydatabase-port
port: 3306
targetPort: 3306
selector:
app: mydatabase
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mydatabase-deployment
labels:
app: mydatabase
spec:
selector:
matchLabels:
app: mydatabase
strategy:
type: Recreate
template:
metadata:
labels:
app: mydatabase
spec:
containers:
- name: mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- name: MYSQL_DATABASE
value: "mydatabase"
- name: MYSQL_USER
value: "mydatabase"
- name: MYSQL_PASSWORD
value: "mydatabase"
ports:
- containerPort: 3306
name: mysql
restartPolicy: Always
服务是在esa-local-dev
命名空间上创建的。在你的 yaml 中,你有:
apiVersion: v1
kind: Service
metadata:
name: mydatabase
namespace: esa-local-dev
...
您可以通过运行来查看服务,
$ kubectl get services -n esa-local-dev