I'm running Kubernetes with docker desktop on windows. DD is up-to-date, and the kubectl version
command returns 1.22 as both the client and server version.
I executed kubectl run my-apache --image httpd
, then kubectl get all
, which only shows
There is no deployment or replicaset as I expect. This means some commands, such as kubectl scale
doesn't work. Any idea what's wrong? Thanks.
CodePudding user response:
The kubectl run
command create pod not deployment, I mean it used to create in the past before kubernetes version 1.18 I guess.
For deployment you have run this command
kubectl create deployment my-apache --image httpd
CodePudding user response:
You basically spin up a pod in the default namespace, if you want to deploy your app using deployment you should have a deployment.yml
file and use :
kubectl apply -f <depoyment_file>
Example to spin-up 3 Nginx pods:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Side note: There are 2 approaches when creating basic k8s objects:
- IMPERATIVE way:
kubectl create deployment <DEPLOYMENT_NAME> --image=<IMAGE_NAME:TAG>
- DECLARATIVE way:
kubectl create -f deployment.yaml