Kubernetes commands list

Apply resource:

kubectl apply -f resource.yaml

Apply resource passed into stdin:

cat resource.yaml | kubectl apply -f -

Edit the resource and then apply it:

kubectl apply -f resource.yaml --edit -o yaml

Create namespace:

kubectl create namespace my-namespace

Secret docker registry:

Create a new secret for use with Docker registries.

Dockercfg secrets are used to authenticate against Docker registries.

When using the Docker command line to push images, you can authenticate to a given registry by running: '$ docker login DOCKERREGISTRYSERVER --username=DOCKERUSER --password=DOCKERPASSWORD --email=DOCKER_EMAIL'.

That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to authenticate to the registry. The email address is optional.

When creating applications, you may have a Docker registry that requires authentication. In order for the nodes to pull images on your behalf, they have to have the credentials. You can provide this information by creating a dockercfg secret and attaching it to your service account.

kubectl create secret docker-registry my-secret \
--docker-server=DOCKER_REGISTRY_SERVER \
--docker-username=DOCKER_USER \
--docker-password=DOCKER_PASSWORD \
--docker-email=DOCKER_EMAIL

Services

ClusterIP

# ClusterIP
kubectl create service clusterip my-cs --tcp=5678:8080

# ClusterIP in headless mode
kubectl create service clusterip my-cs --clusterip="None"

External Name

kubectl create service externalname my-ns --external-name example.com

LoadBalancer

kubectl create service loadbalancer my-lbs --tcp=5678:8080

NodePort

kubectl create service nodeport my-np --tcp=5678:8080

Service Account

kubectl create serviceaccount my-sa

Source